Rails 3 - Add existing child to parent with a nested form?

If you want many users coupled to many events, you will need has_many :through relationship. In that case, a relation builds a new row in the database, and in that case it is easier to use the cocoon-gem to dynamically link and unlink pages.

Up vote 1 down vote favorite share g+ share fb share tw.

My application has a form to update an Event. I'd like to be able to add an existing user to this event with a nested form. I use the Ryan Bates "nested_form" gem.

It works great to delete an existing user but how can I add an existing one just with his username? Model : class Event true end Controller : def update if @event. Update_attributes(params:event) redirect_to @event else render :edit end end View : = f.

Fields_for :users do |users_form| = users_form. Text_field :username = users_form. Link_to_remove "Remove user" = f.

Link_to_add "Add a user", :users = f. Submit Thanks in advance! Ruby-on-rails ruby-on-rails-3 nested-forms link|improve this question asked Jun 9 '11 at 11:52invaino927 82% accept rate.

– nathanvda Jun 9 '11 at 13:27 A user can be linked to multiple events :) – invaino Jun 9 '11 at 15:36 I watched your cocoon gem which is impressive but I didn't find a way to add an existing child with it – invaino Jun 9 '11 at 15:49.

If you want many users coupled to many events, you will need has_many :through relationship. In that case, a relation builds a new row in the database, and in that case it is easier to use the cocoon-gem to dynamically link and unlink pages. I answered a very similar question, also coupling events and users, here.

If you have any more questions, let me know.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions