我正在使用重新文件创业板多次上传。图像显示得很好。我想要创建一个销毁行动,以显示在图像下使用link_to。我该如何写我的毁灭行动,在link to**?** 的道路应该是什么,谢谢!
show.html.erb
<% @post.images.each do |i| %>
<%= attachment_image_tag(i, :file, :fill, 350, 350, format: "jpg") %>
<%= link_to 'Delete', **?????**, method: :detele %>
<% end %>我可以使用控制台删除第一个帖子中的第二个图片,比如这个p=Post.first.images.find 2,然后是p.destroy。
我的帖子和形象模型是
class Image < ActiveRecord::Base
belongs_to :post
attachment :file
end
class Post < ActiveRecord::Base
has_many :images, dependent: :destroy
accepts_attachments_for :images, attachment: :file, append: true
endconfig/scripes.rb
Rails.application.routes.draw do resources :posts do resources :images end root 'posts#index' end
发布于 2015-09-08 05:22:58
<% @post.images.each do |i| %>
<%= attachment_image_tag(i, :file, :fill, 350, 350, format: "jpg") %>
<%= link_to 'Delete', post_image_path(@post.id, i.id), method: :detele %>
<% end %>只是粘贴你的图像路径。如果您的路由配置正确,这就足够了。
更新
你的路线应该是这样的
resources :posts do
resources :images
endhttps://stackoverflow.com/questions/32449748
复制相似问题