f.label不使用haml中的块

时间:2013-01-22 11:26:08

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

我有以下haml代码

form_for @user_notification_settings_form do |f|
  = f.label :follow do
    div dummy

但它会生成

<label for="user_notification_settings_form_follow">
  foruser_notification_settings_form_follow
</label>

我期待它生成的地方

<label for="user_notification_settings_form_follow">
  <div>dummy</div>
</label>

我已经发现:[/ p> label_tag中的{p> form_tag_helper&block,但当它在content_tag中调用tag_helper时,&block现在变为零

  def label_tag(name = nil, content_or_options = nil, options = nil, &block)
    options = content_or_options if block_given? && content_or_options.is_a?(Hash)
    options ||= {}
    options.stringify_keys!
    options["for"] = sanitize_to_id(name) unless name.blank? || options.has_key?("for")
    content_tag :label, content_or_options || name.to_s.humanize, options, &block
  end
  def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
    if block_given?
      options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
      content_tag_string(name, capture(&block), options, escape)
    else
      content_tag_string(name, content_or_options_with_block, options, escape)
    end
  end

1 个答案:

答案 0 :(得分:0)

您只需制作%div元素,然后将标签的文本嵌套在其中。

form_for @user_notification_settings_form do |f|
  = f.label :follow do
    %div 
      dummy