Skip to content

Instantly share code, notes, and snippets.

@wejrowski
Created August 17, 2011 22:10
Show Gist options
  • Select an option

  • Save wejrowski/1152768 to your computer and use it in GitHub Desktop.

Select an option

Save wejrowski/1152768 to your computer and use it in GitHub Desktop.
Passing Blocks to Rails partials
<%
#
# I originally needed to create a sidebar partial that had a div area where I could place custom links into. Finally found it.
# When I was trying to figure this out before and realized I needed to pass the view into :layout, rather than just using render 'layout'. Not sure why the block can't be passed otherwise but nonetheless...
#
# For explanation of options see
# http://guides.rubyonrails.org/layouts_and_rendering.html#options-for-render
#
%>
<%= render :layout=>'my/layout' do %>
<% #some extra block passing rails magic
%>
<%=link_to products_path, :class => 'button continue' do %>
<%= image_tag('/images/topchoice/button-arrow-left.png', :class=>'arrow') %> Shop More
<% end %>
<% end %>
<%
# Then just put this in your layout
%>
<%= yield %>
@emad-elsaid
Copy link
Copy Markdown

Oh my god, i searched for this for a long time, it's not obvious at all, what is it not working without "layout".

@sambecker
Copy link
Copy Markdown

This is great. Is there any way to achieve this effect with two blocks? Or two chunks of HTML?

@soulfly
Copy link
Copy Markdown

soulfly commented Sep 6, 2018

Sweet! thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment