rails 2.2 block in view
block in view before
concat source code
其他學到的 concat, capture, yield,content_tag
concat
capture
yield, content_for
content_tag
2008年12月17日 星期三
Block in views, concat, capture, content_for,yield,content_tag
rails 2.2 block in view
block in view before
concat source code
其他學到的 concat, capture, yield,content_tag
concat
capture
yield, content_for
content_tag
block in view before
concat source code
其他學到的 concat, capture, yield,content_tag
concat
capture
yield, content_for
content_tag
標籤:
Block in views,
capture,
concat,
content_for,
content_tag,
yield
2008年7月17日 星期四
capture, content_for
http://api.rubyonrails.org/classes/ActionView/Helpers/CaptureHelper.html
如果你想改layout的東西, 可是又只想是在某個controller/action下去做變動, 除了在
layout判斷controller.controller_name 和 controller.action_name之外, 還
有另外一個選擇, 那就是capture
[某個action]
<% @header = capture do %>
<%= link_to "#{@user.name}的早起紀錄",{:controller => 'main', :action => 'index'} ,:class => 'ebhead'%>
<% end %>
因為只有在這個action view裡, @header才會產生
就可以直接在layout裡去看這個variable在不在, 不用在那邊判斷controller name, action name
<% if @header %>
<%= @header %>
<% else %>
<a href='<%= home_url %>'> 早 鳥 <span >i wake la</span> </a>
<% end %>
標籤:
capture,
content_for,
rails
2008年5月18日 星期日
rails 頁面產生的順序
content => layout, 所以如果有些include的東西如果放在layout 而且還在head 後面就不會include進來, 因為head早就生完了
==layout: application.rhtml==
<head>
... //head在這
<%= yield :page %>
</head>
<body>
<%= render :partial => 'not_include' %> // 到body才去生這個partial
</body>
==partial: not_include.rhtml==
<% content_for :page do%>
<%= javascript_include_tag "hope_in_head" %> // 想要生在head裡, 可是head早就生完了
<% end %>
標籤:
content_for,
rails
訂閱:
文章 (Atom)