我正在尝试为网格创建一个帮助器,我正在使用此代码:
app / helpers / application_helper.rb中的:
module ApplicationHelper
def grid_helper(names)
names.each_slice(2) do |name1, name2|
haml_tag 'div', class: 'column' do
haml_tag 'div', class: 'thumb' do
haml_concat link_to name1[:url] do
image_tag name1[:thumb], alt: name1[:description], size: '36x36'
end
end
haml_tag 'div', class: 'thumb' do
haml_concat link_to name2[:url] do
image_tag name2[:thumb], alt: name2[:description], size: '36x36'
end
end
end
end
end
end
呼吁haml:
#mydiv
- games = [{thumb: 'foo', description: 'foobar', url: 'foo'}, {thumb: 'bar', description: 'foobarbaz', url: 'bar'}]
- grid_helper(games)
所以这个用html:
<div class="column">
<div class="thumb">
<a href="/">foo</a>
</div>
<div class="thumb">
<a href="/">bar</a>
</div>
</div>
link_to
无法正常工作且image_tag
对我的帮助无效,有人可以提供帮助吗?
Obs:我正在使用Rails4,Ruby2和sass / haml
答案 0 :(得分:1)
问题出在以下几行:
haml_concat link_to name1[:url] do ...
该块由haml_concat
代替link_to
使用。你可以像那样重写它
haml_concat(link_to name1[:url] { image_tag name1[:thumb], alt: name1[:description], size: '36x36' })