Ruby on Rails
Saturday, January 20, 2018
On Saturday, January 20, 2018 at 10:49:50 AM UTC-5, Walter Lee Davis wrote:
> On Jan 19, 2018, at 7:37 PM, fugee ohu <fuge...@gmail.com> wrote:
>
> can create person objects with Adress.....person.new but if I'm creating a new person object from @person from a form, how do i create the entry to the relationships table since I don't have @person.id yet
>
>
You don't need to do that -- Rails cleans up those values for you when it saves the parent. So if you have
@user = User.new(user_params)
@widgets = @user.widgets.build(widget_params)
When you save @user, the @widgets will be saved as well, and the correct ID will be put into each of the @widgets.
Walter
i was actually able to get @person.id after if @person.save Relationship.find_or_create_by(person_id: @person.id ...
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/614c7802-c2b9-4e03-b276-3f1c857bed02%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment