insert into 2 joined tables from the same form submission

16 views
Skip to first unread message

fugee ohu

unread,
Dec 29, 2015, 8:36:22 AM12/29/15
to Ruby on Rails: Talk
user has many addresses so i wanna put address fields in the new user registration form, i don't know how i would do it, i'm trying to conceptualize it

Walter Lee Davis

unread,
Dec 29, 2015, 8:47:59 AM12/29/15
to rubyonra...@googlegroups.com

> On Dec 29, 2015, at 8:36 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> user has many addresses so i wanna put address fields in the new user registration form, i don't know how i would do it, i'm trying to conceptualize it
>

Have a look at accepts_nested_attributes_for and the fields_for form helper. This is a really well-solved problem in Rails. If you use simple_form, there are helpers in there for this pattern as well. And as usual, Ryan Bates wrote about this (and made a great gem for it) about a million internet-years ago: https://github.com/ryanb/nested_form and http://railscasts.com/episodes/196-nested-model-form-revised

Walter

> --
> 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-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5898a890-523e-48b2-bf2e-0d12d992c18c%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

fugee ohu

unread,
Dec 29, 2015, 7:27:28 PM12/29/15
to Ruby on Rails: Talk
Can you tell me how to display an attribute from the parent in a view please

Walter Lee Davis

unread,
Dec 29, 2015, 8:51:53 PM12/29/15
to rubyonra...@googlegroups.com

> On Dec 29, 2015, at 7:27 PM, fugee ohu <fuge...@gmail.com> wrote:
>
> Can you tell me how to display an attribute from the parent in a view please

Show your work! What have you tried already?

Walter
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bd965c24-fcdd-401b-9b93-859532f97851%40googlegroups.com.

fugee ohu

unread,
Dec 29, 2015, 9:50:56 PM12/29/15
to Ruby on Rails: Talk
thanks, i found it here http://guides.rubyonrails.org/association_basics.html i just did @child.parent.attribute that works ~ thanks again
Reply all
Reply to author
Forward
0 new messages