這似乎是一個非常簡單的問題。假設我要檢查動態,以一些屬性添加到一些標籤在一些Helper Module
條件:將動態屬性添加到content_tag
def add_tag(hash)
content_tag(:div, class: "some_class", rows: "#{check_rows(hash)}")
end
def check_rows(hash)
hash[:rows].nil? ? "" : hash[:rows]
end
這工作得很好,但我不想做rows
出現內部生成的標籤,如果hash[:rows].nil?
。所以,我想這個
content_tag(:div, class: "some_class", "#{check_rows(hash)}")
和
def check_rows(hash)
hash[:rows].nil? ? "" : ":rows => hash[:rows]"
end
但"#{check_rows(hash)}"
不被認可。有沒有辦法做到這一點 ?
你是什麼意思''{#check_rows(hash)}「不被識別」? – mdesantis