Rails 4 - rendering a collection with a partial name different to the variable
ruby-on-rails, ruby-on-rails-4
Solution
http://guides.rubyonrails.org/layouts_and_rendering.html Check this for changing the name Let say you have products and want to use as item then just do like
<%= render partial: "product", collection: @products, as: :item %>
i recommend you to check this too. http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html
Problem
I have the following partial `posts/post_preview` in my project: ``` .post %h2= link_to(post.title, post) .post-body= simple_format(post.body) %ul - post.tags.each do |tag| %li= tag ``` I want to render this partial for a collection name `@posts`, like so: ``` render partial: 'post_preview', collection: @posts ``` However, `render` by default passes each member of the collection as a local variable named after the partial. Is there any way I can change this so each member of `@posts` is passed into the partial in a variable named `post`?