The other day I stumbled on Sandi Metz's rules, and one of them reads
When a call comes into your Rails controller, you can only instantiate one object to do whatever it is that needs to be done.
Still pretty new to Rails, but I always thought that my controller methods had some smell in them, and this confirmed it. I have a dashboard view for a parent model that displays information about their children (a different model) and the children's challenges(another model), all with different controllers. Here is an example of one of our controller methods.
def dash
@parent = current_user
@children = @parent.children
@completed_challenges = @parent.assigned_challenges.where("parent_id =?", @parent.id).where("completed =?", true)
@validated_challenges = @parent.assigned_challenges.where("parent_id =?", @parent.id).where("validated =?", true)
@enabled_rewards = @parent.enabled_rewards.where("parent_id =?", @parent.id)
end
I was wondering if I could send multiple requests to get all of these objects from their respective controllers as opposed to lumping them all in one request. I know I can do this with Ajax, but is there a way just doing multiple http requests when the page is loading?
I appreciate the help!