我有一个 Post 模型
has_many photos
Post 模型有
accepts_nested_attributes_for :photos
在我的帖子编辑表单中,我显示了当前与帖子关联的所有图像
<% for photo in @post.photos %>
<%= image_tag(photo.avatar.url(:thumb)) %> <%= link_to "Remove Photo", post_photo_path(@post, photo), :method => :delete %>
<% end %>
将鼠标悬停在“删除照片”链接上时,路径如下所示
http://localhost:3000/posts/17/photos/45
我得到未初始化的常量 PhotosController,但这是意料之中的,因为没有。
我的问题是我是否创建一个并在那里进行破坏操作,只会删除该照片..这是解决方法还是有更好的方法?
编辑
照片控制器
def destroy
@photo = Photo.find(params[:id])
@photo.destroy
redirect_to edit_post_path, :notice => "Successfully deleted Photo"
end
路线
resources :posts do
resources :photos
resources :departments
end
耙子路线
edit_post GET /posts/:id/edit(.:format)
谢谢