【问题标题】:haml_tag not returning any stringhaml_tag 不返回任何字符串
【发布时间】:2011-06-30 02:35:29
【问题描述】:

您好,我尝试复制旧的 haml_tags,但似乎它们不适用于 Rails 3.1rc4,或者我做错了什么。谁能指出我正确的方向?

def bonus_value_of(stat)
  bonus = current_user.character.send("bonus_#{stat}".to_sym)
  capture_haml do
    haml_tag :span, :class => "positive" do
      "+#{bonus}"
    end
  end
end

这就是我调用的代码

= bonus_value_of(stat)

我得到的只是一个空白跨度,有正类但没有内容(甚至没有加号)

这是一个错误吗?

【问题讨论】:

    标签: haml helpers ruby-on-rails-3.1


    【解决方案1】:

    这是我的版本。

    1.你的助手应该在控制器的助手中,而不是像某些文章中描述的那样在module Haml::Helper中。

    2.将您的助手更改为:

    def bonus_value_of(stat)
      bonus = current_user.character.send("bonus_#{stat}".to_sym)
      haml_tag :span, :class => "positive" do
        haml_concat "+#{bonus}"
      end
    end
    

    然后像这样在你的视图中使用它:

    - bonus_value_of(stat)
    

    【讨论】:

      【解决方案2】:

      我刚碰到这个。我需要将跨度文本作为第二个值传递给haml_tag

      def bonus_value_of(stat)
        bonus = current_user.character.send("bonus_#{stat}".to_sym)
        capture_haml do
          haml_tag :span, "+#{bonus}", :class => "positive"
        end
      end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-10-15
        • 1970-01-01
        • 1970-01-01
        • 2011-05-08
        • 1970-01-01
        • 2020-09-16
        • 2015-02-18
        相关资源
        最近更新 更多