2010-08-23 56 views
0

我正在将一个旧程序转换为haml,并且我的自定义formbuilder出现问题。问题只是在字段标签和输入标签之间添加换行符。haml formbuilder

原来这里是FormBuilder:

# Custom FormBuilder 
class SuperFormBuilder < ActionView::Helpers::FormBuilder 

    # Create an array of helpers to override with our label builder 
    helpers = field_helpers + 
      %w{calendar_date_select date_select datetime_select time_select} + 
      %w{collection_select select country_select time_zone_select} - 
      %w{hidden_field label fields_for} # Don't decorate these 

    helpers.each do |name| 

    define_method(name) do |field, *args| 

     # Get the hash option (EG the field involved) 
     options = args.extract_options! 

     # Create a label for that field 
     label = label(field, options[:label], :class => options[:label_class]) 

     # Create an inline error 
     error = error_message_on(field) 

     # Wrap label in paragraph, include the original helper EG: text-field 
     @template.content_tag(:p, label + "<br />" + super + error) #wrap with a paragraph 
    end 
    end 

    # Override the submit button 
    def submit 
    # Calculate custom text for submit button. 
    prefix = object.new_record? ? "Create" : "Update" 

    # Wrap submit button in paragraph tags and add custom text. 
    @template.content_tag(:p,super(prefix, :id => "apply")) 
    end 
end 

如果我用%BR如该< BR/>是完全不工作。有没有办法将这个改为haml很好?

回答

0

如果您只是使用tag("br")会发生什么?

+0

玩了,因为我已经发现了这一段时间之后的工作原理: @ template.content_tag(:P,标签+ @ template.tag( “BR”)+超+误差) 是有办法最小化这一点? – map7 2010-08-23 05:02:37

+0

@ map7八年之后(仍然)使用'concat'的可能性。 – Felix 2018-02-21 15:52:46