Question

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.

Was it helpful?

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

OTHER TIPS

I see you already tried, but I had the same problem (rendering the output again as escaped HTML) with rails 2.3.14. Fixing

= fields_for .....

with

- fields_for .....

solved it for me.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top