我正在使用Paperclip进行多张图片上传。上传的图片显示在我的@post视图中:
<% for asset in @post.assets %>
<%= link_to image_tag(asset.image.url(:thumb)), asset.image.url(:big), :class => "fancybox", :rel => "gallery" if asset.image? %>
<% end %>
我的问题是我希望这些图片也能在另一个视图中显示,如下所示:
<% for asset in @post.assets %>
<%= image_tag asset.image.url(:thumb) if asset.image? %>
<% end %>
查看控制器:
class HomeController < ApplicationController
def school_news
@posts = Post.page(params[:page]).per(4).order('posts.id DESC')
end
end
现在我有这个错误:
NoMethodError in Home#school_news
Showing D:/Projects/livu_pamatskola/app/views/home/school_news.html.erb where line #17 raised:
undefined method `assets' for nil:NilClass
Extracted source (around line #17):
14: <%= link_to 'Lasīt vairāk...', posts %>
15: </div>
16: </div>
17: <% for asset in @post.assets %>
18: <%= image_tag asset.image.url(:thumb) if asset.image? %>
19: <% end %>
20: <div id="separator"></div>
我做错了什么?