Help, I''m trying to pass a course_id from a collection_select and can''t figure out how to do it. If I hard-code my method: def move_stu Enrollment.update_all(["course_id = ?", "12" ], :student_id => params [:student_ids]) ## end It works perfectly. The enrollment updates the student''s course_id to 12. Instead of hard-coding it, I''d like users to be able to select the course they want to move the student to. My collection_select looks like this (and I don''t get any errors): <%= collection_select(:student, :course_id, current_user.courses, :id, :name, :include_blank => true) %> BUT I haven''t been able to pass :id to the move_stu method. I''ve tried this: def move_stu Enrollment.update_all(["course_id = ?", id ], :student_id => params [:student_ids]) ## end but all that passes in is a random 8 digit id from ??? (not the :id from the collection_select) Any ideas??? thank you in advance!
Frederick Cheung
2009-Jul-30 13:57 UTC
Re: help passing an id from a collection_select to my method
On Jul 30, 9:54 am, D <demetri...-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org> wrote:s:> > def move_stu > Enrollment.update_all(["course_id = ?", id ], :student_id => params > [:student_ids]) > > ## > end > > but all that passes in is a random 8 digit id from ??? (not the :id > from the collection_select) >The id you are using there is the id of the current controller instance. Just as you pick the student_id out of the params hash, the course will be somewhere in params too. If you look in your development.log or play around in the debugger you should be able to figure out where in the params hash it is. Fred> Any ideas??? thank you in advance!