Reputation: 149
So I am building this ruby on rails webapp. I have two models: Courses and lessons. Courses has many lessons and lesson belongs to course. I have the forms running just fine but what i want to do is pass the :course_id to the lesson form to be able to keep track of what course the lesson belongs to. ( I have included a course_id value in the lesson table.
Basically, my question is how can i pass the :id of the course onto the lesson form?
Upvotes: 1
Views: 56
Reputation: 14750
Why not just assign the new lesson
the course id?
Instead of doing
@lesson = Lesson.new
do
@lesson = Course.find(params[:course_id]).lessons.new
or something of that sort.
Or (better):
@lesson = Course.find(params[:course_id]).lessons.build
Upvotes: 2
Reputation: 4003
A hidden field?
Not sure what you want to do with this course_id in the form, but if it's just to pass it back on submit, look into Nested Resources
Upvotes: 0