2015-12-03 26 views
0

試圖創建一個簡單的輔助,這將返回我的看法:導軌4 - HTML在助手返回一個Hash

<hr id="effects"> 

我創建看起來像這樣的幫手:

def bar(id) 
    content_tag(:hr, id: id) 
end 

當我打電話

<%= bar("effects") %> 

助手正確顯示<hr>,而是直接顯示像012頁的ID

我假設我做錯了,但似乎無法找到任何可以幫助我的東西。我感謝任何幫助。

回答

1

content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)

第二個參數是內容,你可以嘗試

def bar(id) 
    content_tag(:hr, "", id: id) 
end 
1

由於每documentation

def bar(id) 
    content_tag(:hr, "", id: id) 
end 

不過,我不知道爲什麼你已經創造了這樣的helper方法。你可以直接在視圖上執行它(也推薦它)。