Skip to content

Instantly share code, notes, and snippets.

@scottillogical
Created January 14, 2011 22:51
Show Gist options
  • Save scottillogical/780446 to your computer and use it in GitHub Desktop.
Save scottillogical/780446 to your computer and use it in GitHub Desktop.
# application.html.erb
<%=raw yield_section(1, :description) %>
# application_helper.rb
def yield_section(number, content_name)
content = find_dynamic_content(number)
return content if content
yield content_name # throws a no block given (yield) error, it's supposed to yield to the view
end
# show.html.erb
<% content_for :description %>
DEFAULT CONTENT HERE
<% end %>
# i could do it like this
<% if yield_section(1) %>
<div><%= yield_section(1) %></div>
<% else %>
<div>yield :description</div>
<% end %>
@scottillogical
Copy link
Author

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