ubuntu, ror, jQuery, css, website memo
太嫩, 沒啥心得, 用來紀錄每天學的
2009年9月3日 星期四
block in view, yield, capture
Blocks in View
Pretty Blocks in Rails Views
def admin_area(&block)
if admin?
concat content_tag(:div, capture(&block), :class => 'admin'), block.binding
end
end
def link_to(*args,&block)
if block_given?
concat(super(capture(&block), *args), block.binding)
else
super(*args)
end
end
show.html.erb
<% render(:layout => 'rounded') do %>
Rounded corners are so Web 2.0.
<% end %>
_rounded.html.erb:
<%= yield %>
_content.html.erb
Rounded corners are so Web 2.0.
show.html.erb
<%= render :partial => "content", :layout => "rounded" %>
<% render(:layout => 'rounded', :locals => {:title => "What I think about rounded corners", :id => "rounded_thoughts", :background => true}) do %>
Rounded corners are so Web 2.0.
<% end %>
<[div class="rounded_corner_top" id="<%= id %>"]> <[/div]>
<% if title %>
<%= title %>
<% end %>
<[div class="<%= background ? "rounded_corner_content" : "rounded_corner_no_bg" %>"]><%= yield %><[/div]>
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言