【问题标题】:Ruby On Rails helper for create grids用于创建网格的 Ruby On Rails 助手
【发布时间】:2014-02-25 13:24:46
【问题描述】:

我正在尝试为网格创建一个助手,我正在使用此代码:

在 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 在我的helper 上真的不能工作,有人可以帮忙吗?

Obs:我正在使用 Rails4、Ruby2 和 sass/haml

【问题讨论】:

  • link_to之前删除p
  • @Baldrick 已删除,但这并没有改变:/

标签: ruby-on-rails ruby-on-rails-4 haml


【解决方案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' })

【讨论】:

    猜你喜欢
    • 2014-03-26
    • 2015-03-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-05
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多