Ton*_*ate 1 routes ruby-on-rails-3
在我的应用程序中,评论属于照片,我正在尝试添加一种方法来销毁评论.
的routes.rb
resources :photos do
resources :comments
end
Run Code Online (Sandbox Code Playgroud)
CommentsController
def destroy
@comment = Comment.find(params[:id])
@comment.destroy
end
Run Code Online (Sandbox Code Playgroud)
照片/ show.html.erb
<% @photo.comments.each do |comment| %>
<%= comment.body %></p>
<p><%= link_to 'Remove comment', comment, :confirm => 'Are you sure you want to remove this comment? This cannot be undone.', :method => :delete %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
我得到的错误是undefined method 'comment' for #<Photo:0x10ace9270>.
我想我可能没有正确设置我的路线,因为当我检查路线时,comment我得到:
rake routes | grep comment
photo_comments GET /photos/:photo_id/comments(.:format) {:action=>"index", :controller=>"comments"}
POST /photos/:photo_id/comments(.:format) {:action=>"create", :controller=>"comments"}
new_photo_comment GET /photos/:photo_id/comments/new(.:format) {:action=>"new", :controller=>"comments"}
edit_photo_comment GET /photos/:photo_id/comments/:id/edit(.:format) {:action=>"edit", :controller=>"comments"}
photo_comment GET /photos/:photo_id/comments/:id(.:format) {:action=>"show", :controller=>"comments"}
PUT /photos/:photo_id/comments/:id(.:format) {:action=>"update", :controller=>"comments"}
DELETE /photos/:photo_id/comments/:id(.:format) {:action=>"destroy", :controller=>"comments"}
Run Code Online (Sandbox Code Playgroud)
有人想过我错在哪里吗?谢谢.
<% @photo.comments.each do |comment| %>
<%= comment.body %></p>
<p><%= link_to 'Remove comment', [@photo, comment], :confirm => 'Are you sure you want to remove this comment? This cannot be undone.', :method => :delete %></p>
<% end %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4212 次 |
| 最近记录: |