Last Updated: February 25, 2016
·
574
· mindeavor

Default variables in Rails 3 view partials

Useful for when you don't want to create another file for a small variation in a partial view:

# products/_block.html.erb
<% show_details = false if local_assigns[:show_details].nil? %>

You can then render it in another view:

# products/show.html.erb
<!-- This works -->
<%= render 'products/block', :show_details => true %>
<!-- This also works -->
<%= render 'products/block' %>