【发布时间】:2015-06-29 15:09:36
【问题描述】:
在我的 Rails 4.2.1 应用程序中,我有 Posts 和 Comments(嵌套在 Posts 中):
# config/routes.rb
resources :posts do
resources :comments
end
我有以下评论部分:
# app/views/comments/_comment.html.erb
<%= comment.body %>
我正在尝试从 Posts 视图中呈现该部分内容:
# app/views/posts/show.html.erb
<% @comments.each do |comment| %>
<%= render 'comments/comment', :locals => { :comment => comment } %>
<% end %>
问题是我在尝试渲染部分时遇到未定义的局部变量或方法“注释”错误。
我对 Rails 很陌生,但在我看来,我正在正确地将 comment 变量传递给部分。我错过了什么明显的东西吗?
谢谢
更新
我在文档中查找错误的位置。见http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials
【问题讨论】:
-
# app/views/comments/_form.html.erb是不是打错字了? -
是的...对不起,修正了错字。
标签: ruby-on-rails ruby partials