Search code examples
ruby-on-rails-3hamlpartial-viewsfields-for

Rails 3: fields_for partial renders twice, once normally and once as escaped output


Trying to render a partial using a fields_for block. The partial renders the form fields fine, but then renders the output again as escaped HTML. The code to call the partial is here (haml):

= fields_for "advertisement[versions_attributes][#{@advertisement.versions.size-1}]".to_sym, @version do |version_fields|
  = render :partial => 'advertisement_versions/fields', :locals => {:f => version_fields}

I've tried using - fields_for and - render, but with no luck. - fields_for won't render the partial, and - render produces the same problem.


Solution

  • = fields_for "advertisement[versions_attributes][#{@advertisement.versions.size-1}]".to_sym, @version do |version_fields|
      = render :partial => 'advertisement_versions/fields', :f => version_fields
    

    If I'm not wrong you can also omit :partial => and just do

    = render 'advertisement_versions/fields', :f => version_fields