ruby - Passing parameters to Rails partial -


in rails 4.2.1 app have posts , comments (which nested within posts):

   # config/routes.rb     resources :posts       resources :comments    end 

i have following comments partial:

   # app/views/comments/_comment.html.erb     <%= comment.body %> 

i'm trying render partial within posts view:

   # app/views/posts/show.html.erb     <% @comments.each |comment| %>      <%= render 'comments/comment', :locals => { :comment => comment } %>    <% end %> 

the problem i'm getting undefined local variable or method "comment" error when trying render partial.

i'm pretty new rails looks me passing comment variable partial correctly. missing obvious?

thanks

update

i looking in wrong spot in documentation. see http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials

enter image description here

either add in partial

<%= render partial: 'comments/comment', :locals => { :comment => comment } %> 

or render collection: via rails using model name

<%= render @comments %> 

or explicitly

<%= render partial: 'comments/comment', collection: @comments %> 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -