Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Things to refactor #74
@allthesignals Found this pattern for nested and un-nested resources, but more Googling seems to reveal that your pattern is actually not far off from the accepted practice: http://stackoverflow.com/questions/21766957/how-to-manage-both-nested-and-not-nested-resources
@mzagaja Rails docs seem to suggest nested resources should work out of the box... see the table here: http://guides.rubyonrails.org/v3.2.9/routing.html#nested-resources.
Maybe it's not saying it will handle the controller logic of only getting particular related resources when they're nested? Thoughts?
It's just sad to have to write all those methods!
So http://railscasts.com/episodes/139-nested-resources?autoplay=true at 4m mark shows a pattern whereby the child nested controller needs to be modified to summon the parent nested resource and then summon the child resources through the parent. If we follow this pattern to refactor your code it'd be something like
The StackOverflow above demonstrates that if you have both nested and un-nested routes, that your if params logic is unavoidable. Definitely agree that it could be more elegant.