我看到了一些類似的問題,但沒有成功。 我想在我的主頁上顯示3條最新帖子。在主頁欄目上顯示3條最新帖子
我定義我的PostsController
def noticia
@posts = Posts.all(:limit => 3)
end
helper_method :noticia
這種方法,我調用這個對我的看法
- if @noticia
%h4.feed
A Sair
%h6
%span= @noticia.created_at.strftime("%d %b. %Y")
= link_to @noticia.content, posts_path
%p
- if current_admin
= link_to "Adicionar notícia", new_post_path
它給NoMethodError
undefined method `each' for #<Post:0x00000102fb6fc8>
默認範圍是否有限制? – Swards
您是否在您的視圖中引用@posts? – Swards