Scenario: a user (class: User
) wants to apply to a course (class: Course
) online, by creating an application (class Application
).
They visit an application page, at /applications/:id
where id is the course id. This is the controller:
def new
@course = Course.find_by_id(params[:id])
@application = Application.new
end
def create
@application = Application.new(application_params)
@course = Course.find_by_id(params[:id])
@application.course_id = @course.id
@application.save
end
This line fails
@course = Course.find_by_id(params[:id])
because in the method that handles the POST request you can't access the parameters, but I require them to set the course_id on the application.