Tag model
10 votes
2 comments
4712 views
Complex finders in controller make application hard to maintain. Move them into the model as named_scope can make the controller simple and the complex find logics are all in models.
implemented8 votes
7 comments
6693 views
5 votes
0 comments
8584 views
Do not assign the model's attributes directly in controller. Add model virtual attribute to move the assignment to model.
implemented3 votes
0 comments
2895 views
Use model callback can avoid writing some logic codes in controller before or after creating, updating and destroying a model.
7 votes
0 comments
3227 views
Replace Complex Creation with Factory Method
Sometimes you will build a complex model with params, current_user and other logics in controller, but it makes your controller too big, you should move them into model with a factory method
implemented3 votes
3 comments
4790 views
Move Model Logic into the Model
In MVC model, controller should be simple, the business logic is model's responsibility. So we should move logic from controller into the model.
implemented3 votes
0 comments
2500 views
model.collection_model_ids (many-to-many)
When you want to associate a model to many association models by checkbox on view, you should take advantage of model.collection_model_ids to reduce the code in controller.
6 votes
2 comments
4526 views
Use accepts_nested_attributes_for to make nested model forms much easier, this feature is provided by rails 2.3
5 votes
3 comments
2359 views
Keep Finders on Their Own Model
According to the decoupling principle, model should do finders by itself, a model should not know too much about associations finders logic.
implemented5 votes
3 comments
2318 views
named_scope is awesome, it makes your codes much more readable, you can also combine named_scope finders to do complex finders.
