01 Mar '13, 5pm

"ActionView::Helpers::CaptureHelper"

Calling #content_for stores a block of markup in an identifier for later use. You can make subsequent calls to the stored content in other templates, helper modules or the layout by passing the identifier as an argument to content_for . Note: yield can still be used to retrieve the stored content, but calling yield doesn’t work in helper modules, while content_for does. Examples <% content_for :not_authorized do %> alert('You are not authorized to do that!') <% end %> You can then use content_for :not_authorized anywhere in your templates. <%= content_for :not_authorized if current_user.nil? %> This is equivalent to: <%= yield :not_authorized if current_user.nil? %> content_for , however, can also be used in helper modules. module StorageHelper def stored_content content_for (:storage ) || "Your storage is empty" end end This helper works just like normal helpers. <%= stor...

Full article: http://api.rubyonrails.org/classes/ActionView/Helpers/Cap...

Tweets