Could this be done with fields_for?
On Friday, 29 June 2012 15:02:52 UTC-6, sheamus wrote:
>
> Say I have a Dog that has_may legs (In this case we don't care how many).
> In the _form for Dog, I would like to assign a pre-existing let to him. I
> would like to do something like this:
>
> <%= f.collection_select :leg_1, Leg.select { |l| l.dog_id == nil }, :id,
> :description %>
> <%= f.collection_select :leg_2, Leg.select { |l| l.dog_id == nil }, :id,
> :description %>
>
> Then in my controller's create action:
>
> @dog = Dog.new(params[:dog])
> @dog.save
> leg = Leg.find(params[:leg_1])
> leg.dog = @dog
> leg.save
>
> The problem is that the collection_select is trying to set the leg_1 value
> as part of Dog, which of course does not exist. Do I need to create 'view
> model' for doing this?
>
> Thanks,
> ~S
>
>
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/FJhqhsHfyWYJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en-US.