实例变量未传递给partial,因为我面临未定义的方法错误。实例变量未传递给部分(rails 5)
文章控制器:
def index
@articles = Article.order("created_at DESC").all
end
条部分(_article.html.erb)
<h3><%= link_to article.title, article_path(article) %></h3>
index.html.erb
<%= render 'article', article: @articles %>
通过局部变量的替代方式没” t work too:
<%= render 'article', :article => @articles %>
你肯定@articles是有朝一日能设置? – xyious
根据rails 5文档,您可以简单地使用:'render @ articles'并确保'@ articles'确实被设置。 – Magnuss
你的代码不起作用,因为'ActiveRecord :: Collection'上没有方法'title'。 – Ilya