RailsCasts Pro episodes are now free!
Learn more or hide this
UPDATE: I recommend using the "capture" method instead of "with_output_buffer". This has the added benefit of working outside of ERB views. Code below has been updated.
Resources
rvm install ruby-head rvm ruby-head gem install rails --pre bundle install
gem "rails", "3.0.0.beta2"
def admin_area(&block) content = capture(&block) content_tag(:div, content, :class => "admin") end # or def admin_area(&block) content_tag(:div, :class => "admin", &block) if admin? end
<%= form_for @product do |f| %> <% end %> <%= div_for @product do %> <% end %> <% @comments.each do |c| %> <% end %> <% content_for :side do %> <% end %> <% cache do %> <% end %>
<%= admin_area do %> <%= link_to "Edit", edit_product_path(@product) %> | <%= link_to "Destroy", @product, :confirm => "Are you sure?", :method => :delete %> | <%= link_to "View All", products_path %> <% end %>