我使用HAML與我的Rails應用程序的紅寶石和我有一個問題是如何最簡單的方法插入此HAML代碼到一個HTML文件:創建HAML一個幫手或一些與在軌道上
<div clas="holder">
<div class=top"></div>
<div class="content">
Content into the div goes here
</div>
<div class="bottom"></div>
</div>
我想在我這樣的哈姆文件中使用它:
%html
%head
%body
Maybee some content here.
%content_box #I want to get the code i wrote inserted here
Content that goes in the content_box like news or stuff
%body
有沒有更簡單的方法來做到這一點?
我得到這個錯誤:
**unexpected $end, expecting kEND**
與此代碼:
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def content_box(&block)
open :div, :class => "holder" do # haml helper
open :div, :class => "top"
open :div, :class => "content" do
block.call
open :div, :class => "bottom"
end
end
end
請閱讀我對其他答案的評論。在應用速度方面有效嗎? – Lisinge 2010-03-26 14:11:41
速度的差距真的是零。輔助方法很好用。 – shingara 2010-03-26 14:44:50