od razu możesz przejść na jasną stronę mocy i nie robić DHH way - czyli wyciągać logike z kontrolerów https://www.netguru.co/blog/service-objects-in-rails-will-help
bo teraz tworzyć np: usera w kontrolerze, to jest brzydkie, szczególnie w railsach
https://github.com/baartoszsobczynski/e-school-reg/blob/master/app/controllers/students_controller.rb
np:
def update
@school_class = SchoolClass.find(params[:id])
if @school_class.update_attributes(school_class_params)
flash[:success] = "School class updated"
redirect_to @school_class
else
render 'edit'
end
end
nie od tego jest kontroler.
albo tutaj
def link_to_school_class_if_available(student_id)
student = Student.find(student_id)
school_class_available = !student.school_class.nil?
if school_class_available
link_to "#{student.school_class.level}#{student.school_class.indication}", school_class_path(student.school_class.id)
else
"No class"
end
end
ja wiem że to jest active record, ale ... szukać studenta powinien serwis :D