You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a lot going on in politicians_controller.rb:
complex queries
data filtering
api calls
Now that your basic functionality is in place, you're at a really good place to start refactoring. One of the principles of OO design is known as the "single responsibility principle". Right now your controller is doing too much work. Controller should be skinny -- parse the request, gather data for the response/view, -- it should do one thing and one thing well, the glue between the model and the view.
Database queries are perfect for your model, even some basic data filtering is okay there too. You should be able to say things like:
Asking a model instance this kind of "question" is perfectly reasonable and will make your controller code a lot cleaner!
That's a good start. But now we have a new problem. Your Politician model knows too much about the world -- it's asking the Contribution database a lot of hard questions, but it's handling all the database queries itself. Ideally we'd be able to ask the Contribution model questions like:
There's a lot going on in politicians_controller.rb:
Now that your basic functionality is in place, you're at a really good place to start refactoring. One of the principles of OO design is known as the "single responsibility principle". Right now your controller is doing too much work. Controller should be skinny -- parse the request, gather data for the response/view, -- it should do one thing and one thing well, the glue between the model and the view.
Database queries are perfect for your model, even some basic data filtering is okay there too. You should be able to say things like:
Asking a model instance this kind of "question" is perfectly reasonable and will make your controller code a lot cleaner!
That's a good start. But now we have a new problem. Your Politician model knows too much about the world -- it's asking the Contribution database a lot of hard questions, but it's handling all the database queries itself. Ideally we'd be able to ask the Contribution model questions like:
We'll let the Contribution model figure out the details!
The text was updated successfully, but these errors were encountered: