Scenario: the user (class:) User
wants to apply to the course (class:) Course
online by creating an application (class Application
).
They visit the application page, in /applications/:id
, where id is the course identifier. 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 does not work
@course = Course.find_by_id(params[:id])
because in the method that processes the POST request, you cannot access the parameters, but I require that they set course_id in the application.
source
share