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' %>
Written by Gilbert
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Rails
Authors
Related Tags
#rails
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#