Is there a way to use accepts_nested_attributes_for to update another
table from within a controller. For example, I have this in my students
controller:
def student_fail
@student = Subject.find(params[:id]) if params[:id]
@student.build_student_fail
end
def student_fail_finalize
if @student.update_attributes params[:student]
@subject.save
end
end
From the students controller, when the user fills out a form, I just
want to update that information to the student_fail table. Can I achieve
this through the controller using accepts_nested_attributes_for? I don't
want to add anything to the view that indicates the other model. I'm
hoping to do it directly in the controller. Thanks for any suggestions.
Is there a way to use accepts_nested_attributes_for to update another
table from within a controller. For example, I have this in my students
controller:
def student_fail
@student = Subject.find(params[:id]) if params[:id]
@student.build_student_fail
end
def student_fail_finalize
if @student.update_attributes params[:student]
@subject.save
end
end
From the students controller, when the user fills out a form, I just
want to update that information to the student_fail table. Can I achieve
this through the controller using accepts_nested_attributes_for? I don't
want to add anything to the view that indicates the other model. I'm
hoping to do it directly in the controller.
Then you don't need accepts_nested_attributes_for.
However, the controller is the wrong place to sort out the attributes.
Do it in a model or introduce a presenter class. Generally speaking,
any but the most rudimentary logic does not go in the controller.