Ruby on Rails Thursday, April 13, 2017

You _could_ do this, but it's going to be a lot of trouble. Is there a reason why you don't want to add a pets table (and Pet model)? Then it would simply be a matter of adding a couple lines to your User model, and changing the users/_form partial to be a nested form.

class User < ApplicationModel
has_many :pets
accepts_nested_attributes_for :pets
...

class Pet < ApplicationModel
belongs_to :user
...

Walter

> On Apr 13, 2017, at 4:41 AM, fugee ohu <fugee279@gmail.com> wrote:
>
> Let's say I wanna let users add all their pet's on the same form but I don't know how many pets they have I need to let the user provide values for multiple attributes for each pet but won't be creating a pet's table Rather, on completion going to create a text list of the users pets How would I do this?
>
> --
> 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/ac4b98c8-12ee-4ba9-b643-cd759d8c40b8%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
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/4869DA79-07AB-4224-AEB1-27841C67C77B%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment