Skip to content

Instantly share code, notes, and snippets.

@simonbaird
Created August 8, 2012 08:02
Show Gist options
  • Save simonbaird/3293321 to your computer and use it in GitHub Desktop.
Save simonbaird/3293321 to your computer and use it in GitHub Desktop.
block_render rails helper
#
# A trick so you can have partials that take blocks.
# Uses render :layout.
#
# Example:
# <%= block_render 'some_partial_with_a_yield', :foo => 123 do %>
# Any erb here...
# <% end %>
#
def block_render(partial_name, locals={})
render :layout => partial_name, :locals => locals do
yield
end
end
<%= block_render 'block_thing', :foo => '123' do %>
stuff inside here
<% end %>
<%#
#
# Locals:
# right (optional)
#
# Example usage:
# <x= block_render 'shared/more_button_menu' x>
# <li><x= link_to 'Foo, '#' x></li>
# <li><x= link_to 'Bar, '#' x></li>
# <x end x>
#
-%>
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#">More <span class="caret"></span></a>
<ul class="dropdown-menu<%= " pull-right" if defined?(right) && right %>">
<%= yield %>
</ul>
<%= render :partial => 'thing_one', :locals => { :foo => '123' } %>
<%= render 'thing_one', :foo => '123' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment