我正在制作Reddit Clone并刚刚添加了评论。
除了我无法摧毁评论外,一切似乎都有效。
当我点击Destroy时,它会转到我可以查看评论的页面。你可以在这里查看页面http://postimg.org/delete/ehlqrvngq/。
当我点击Destroy时,这是我的服务器 http://postimg.org/delete/equ2hefk8/
这是我的_comments.html.erb
<%= div_for(comment) do %>
<div class="comments_wrapper clearfix">
<div class="pull-left">
<p class="lead"><%= comment.body %></p>
<p><small>Submitted <strong><%= time_ago_in_words(comment.created_at) %> ago</strong> by <%= comment.user.name %></small></p>
</div>
<div class="btn-group pull-right">
<% if comment.user == current_user -%>
<%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' }, class: "btn btn-sm btn-default" %>
<% end %>
</div>
</div>
<% end %>
任何线索?
由于
的routes.rb
Rails.application.routes.draw do
resources :comments
devise_for :users
resources :links do
member do
get "like", to: "links#upvote"
get "dislike", to: "links#downvote"
end
resources :comments
end
root "links#index"
答案 0 :(得分:1)
您的method: :delete
无效。添加method: :delete
应该更改链接以发出DELETE请求,但看起来它正在执行GET请求。
Rails有一些改变请求类型的javascript魔力。你有没有
//= require jquery
//= require jquery_ujs
你的application.js中的?
答案 1 :(得分:1)
检查路线
应该是
resources :links do
member do
get "like", to: "links#upvote"
get "dislike", to: "links#downvote"
end
end
resources :comments
以及
确保布局中的某个地方有<%= javascript_include_tag 'application' %>
现在它应该工作