2013-01-22 34 views
1

我有以下HAML代碼f.label不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> 

Deubugging進入導軌我發現:

label_tagform_tag_helper&block但是當它在tag_helper調用content_tag&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 

回答

0

你只需要進行%div元素,然後窩文本在它的標籤。

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

'%div'的任何原因? –