Rails Best Practices
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.implemented
Use model association to avoid assigning reference in controller.implemented
You can use scope access to avoid checking the permission by comparing the owner of object with current_user in controller.implemented
Do not assign the model's attributes directly in controller. Add model virtual attribute to move the assignment to model.implemented
Use model callback can avoid writing some logic codes in controller before or after creating, updating and destroying a model.
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 methodimplemented
In MVC model, controller should be simple, the business logic is model's responsibility. So we should move logic from controller into the model.implemented
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.
Use accepts_nested_attributes_for to make nested model forms much easier, this feature is provided by rails 2.3