0

I have many models like Entity, person, stuff, box. All of them in controller Create action has this code @entity = Entity.new(entity_params.merge(user: current_user)).

This code makes perfect association when I make each new Model record. But when I fill nested form from Entity.controller only Entity gets user_id association. All other person, stuff ... has NULL on user_id field.

Don't know how to make this work!

1 Answer 1

1

This code looks unusual to me:

@entity = Entity.new(entity_params.merge(user: current_user))

The rails de-facto would be:

@entity = current_user.entities.new

And then active record knows about the association even though the ids are blank initially on the new entity. Not sure this is a complete solution but maybe one of your issues.

Sign up to request clarification or add additional context in comments.

2 Comments

It didn't solve my problem. When I fill nested form through Entity controller I have to make association between Box and User using current_user. Purpose is to know which user is responsible for every record so I can display later correct items to current_user.
Can you add the code for your form view and controller update+new actions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.