Tag model
6 votes
3 comments
3822 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.
implemented7 votes
6 comments
5286 views
5 votes
0 comments
5447 views
Do not assign the model's attributes directly in controller. Add model virtual attribute to move the assignment to model.
implemented2 votes
0 comments
2425 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
2566 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
2 comments
3594 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
2089 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
3719 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
2041 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
2 comments
1952 views
named_scope is awesome, it makes your codes much more readable, you can also combine named_scope finders to do complex finders.
