Helper `fields_for` doesn't work #1204

edison opened this Issue May 22, 2011 · 7 comments

4 participants


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:
So I created a minimal app for test but error still.
I think it's a bug.


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


Here is my test app with log and all included:


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.


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


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.


@thetron is right, it works. Thx!

@edison edison closed this May 22, 2011
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:, 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