i have a Projects
model and User
model. i want to establish has many through association
between these models. now my requirement is i want to list all the users in the multiselect
drop down, in projects/new
form, by this i want to assign all users belongs to this project while creating the project. similarly while creating a new user in users/new
form, i want to list all the projects
in multiselect
dropdown. here what should be controller logic in Projects_controller/create
action and similarly what should be the logic in Users_controller/create
action so that i can save these has many associations in controller?
Asked
Active
Viewed 259 times
-1

John
- 1,273
- 3
- 27
- 61
1 Answers
0
use something like
@user = User.create(...)
@projects = params[:projects].map{|k,v| Project.find(k)}
@user.projects << @projects

tillmo
- 607
- 5
- 11