Screencast: ERB Blöcke in Rails 3

In Rails 3 Beta 2 hat sich die Verwendung von Blöcken in ERB Templates geändert. Ryan zeigt in dieser Woche wie sie benutzt werden können.

 

Download:

Download (21.2 MB, 9:41)
Alternativer Download für iPod & Apple TV (18 MB, 9:41)

 

Resourcen:

 

Quellcode:

[bash]
rvm install ruby-head
rvm ruby-head
gem install rails –pre
bundle install
[/bash]

[ruby]
# Gemfile
gem "rails", "3.0.0.beta2"

# application_helper.rb
def admin_area(&block)
content = with_output_buffer(&block)
content_tag(:div, content, :class => "admin")
end
# or
def admin_area(&block)
content_tag(:div, :class => "admin", &block) if admin?
end
[/ruby]

[html]
<%= form_for @product do |f| %>
<% end %>

<%= div_for @product do %>
<% end %>

<% @comments.each do |c| %>
<% end %>

<% content_for :side do %>
<% end %>

<% cache do %>
<% end %>

<!– products/show.html.erb –>
<%= 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 %>
[/html]