Permalink
Browse files

use content_tag helper

Using content_tag helper helps to avoid manual html generation. It take
care about html safety.
  • Loading branch information...
1 parent 218e87b commit 1cbf61517348c701e08beea41a39f04b35115e6b @lest lest committed Jun 5, 2012
Showing with 4 additions and 8 deletions.
  1. +4 −8 lib/nested_form/builder_mixin.rb
@@ -21,10 +21,9 @@ def link_to_add(*args, &block)
@fields ||= {}
@template.after_nested_form(association) do
model_object = object.class.reflect_on_association(association).klass.new
- output = %Q[<div id="#{association}_fields_blueprint" style="display: none">].html_safe
- output << fields_for(association, model_object, :child_index => "new_#{association}", &@fields[association])
- output.safe_concat('</div>')
- output
+ blueprint = fields_for(association, model_object, :child_index => "new_#{association}", &@fields[association])
+ blueprint_options = {:id => "#{association}_fields_blueprint", :style => 'display: none'}
+ @template.content_tag(:div, blueprint, blueprint_options)
end
@template.link_to(*args, &block)
end
@@ -57,10 +56,7 @@ def fields_for_with_nested_attributes(association_name, *args)
end
def fields_for_nested_model(name, object, options, block)
- output = '<div class="fields">'.html_safe
- output << super
- output.safe_concat('</div>')
- output
+ @template.content_tag(:div, super, :class => 'fields')
end
end
end

0 comments on commit 1cbf615

Please sign in to comment.