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:

rvm install ruby-head
rvm ruby-head
gem install rails --pre
bundle install
# 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
<%= 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 %>

Eingestellt am 05.04.2010 um 10:32

Kategorie: Tutorials

Be Sociable, Share!

Kommentare für diesen Artikel wurden geschlossen.

Suchen auf rubyonrails.de

Aktuelle Rails Version + Abhängigkeiten:

Gem rails-3.0.0
actionmailer (= 3.0.0, runtime)
actionpack (= 3.0.0, runtime)
activerecord (= 3.0.0, runtime)
activeresource (= 3.0.0, runtime)
activesupport (= 3.0.0, runtime)
bundler (~> 1.0.0, runtime)
railties (= 3.0.0, runtime)

Rails auf Rubyforge
Rails auf Github