Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fields_for block sends a form builder object nil #575

Open
dfabreguette opened this issue Jun 3, 2014 · 0 comments
Open

fields_for block sends a form builder object nil #575

dfabreguette opened this issue Jun 3, 2014 · 0 comments

Comments

@dfabreguette
Copy link

When I use the "fields_for" helper, the form builder object is nil.

I have two models AppDomain and AppFeature having a one to many relationship.

Considering the form below :

= form_for [:admin, @admin_app_domain] do |f|
    = fields_for :app_features do |app_feature_form|
        - raise app_feature_form.object.inspect #=> IS NIL !!

Even though I have app_features in @admin_app_domain.app_features, app_feature_form.object is nil.

As a workaround, I tried to pass on the collection (as mentionned in rails doc http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for) and then I got the whole collection in "object" which leads me to an error in my form as I try to call an attribute method on a collection.

= form_for [:admin, @admin_app_domain] do |f|
    = fields_for : app_features, @admin_app_domain.app_features do |app_feature_form|
        - raise app_feature_form.object.inspect #=> IS A COLLECTION

Is it a normal behavior and in that case how are we supposed to use "fields_for" method ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant