I am building an application from ruby ββto rails where I have elements /_item.html.erb. There is a yield statement inside partial, so I can add additional content as needed. In this case, I want to add a specific button to the element, depending on which view causes a partial one.
This is what I tried and it displays partial, but it does not display a block:
_item.html.erb
<%= yield if block_given? %> <div> <%= item.name %> </div>
someview.html.erb
... <% render(:partial => 'items/item', :collection => current_user.items do %> <%= "HELLO" %> <% end %> ...
I also tried using content_for and some other things without success. Is there a way to make specific content inside partial with output? I am currently using Rails3
EDIT:
I found out what it is: a collection hash that makes block insertion impossible.
Both of these code snippets work:
<%= render :layout => 'items/item' do %> Hello world <% end %> <%= render :layout => 'items/item', :locals => {:item => current_user.items.first} do %> Hello world <% end %>
This means that if I do .each, I could do what I want, but that would be ugly code. Does anyone know about this?
source share