Helper `fields_for` doesn't work #1204

Closed
edison opened this Issue May 22, 2011 · 7 comments

4 participants

@edison

This method is returning empty:

<% f.fields_for :asset do |as| %> # not work with or without "="
  <%= as.label :name %><br />
  <%= as.text_area :name %>
<% end %>

I wrote an answer here: http://stackoverflow.com/questions/6086120/helper-fields-for-not-working
So I created a minimal app for test but error still.
I think it's a bug.

@dmathieu

Could you provide this failing app ? Or even better, a failing test !

@edison

Here is my test app with log and all included: https://github.com/edison/rails-test-helper-error

@dmathieu

You shouldn't name your model Asset. When renaming it to something else, it works well.

Edit : my bad. It occurs whenever the relation has accepts_nested_attributes_for.

@edison

In my main app this model is called Traditions::MaterialAsset, doesn't work too.

@thetron

Quite certain this is not a bug.

I posted an answer to your stack overflow question. I tested it with your app an it solves the problem - you don't appear to be calling build_asset (or build_material_asset) on the parent object.

@edison

@thetron is right, it works. Thx!

@edison edison closed this May 22, 2011
@pixeltrix
Ruby on Rails member

As @thetron said it's because the association is empty and is defined as accepting nested attributes. See this article for more information: http://ryandaigle.com/articles/2009/2/1/what-s-new-in-edge-rails-nested-attributes, specifically the section called 'Default Create Form Fields'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment