Tag model

10 votes

2 comments

4712 views

Move finder to named_scope

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
by ihower
ihower

8 votes

7 comments

6693 views

Use model association

Use model association to avoid assigning reference in controller.

implemented
by ihower
ihower

5 votes

0 comments

8584 views

Add model virtual attribute

Do not assign the model's attributes directly in controller. Add model virtual attribute to move the assignment to model.

implemented
by ihower
ihower

3 votes

0 comments

2895 views

Use model callback

Use model callback can avoid writing some logic codes in controller before or after creating, updating and destroying a model.

by ihower
ihower

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

implemented
by ihower
ihower

3 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.

implemented
by ihower
ihower

3 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.

by ihower
ihower

6 votes

2 comments

4526 views

Nested Model Forms

Use accepts_nested_attributes_for to make nested model forms much easier, this feature is provided by rails 2.3

by ihower
ihower

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.

implemented
by ihower
ihower

5 votes

3 comments

2318 views

Love named_scope

named_scope is awesome, it makes your codes much more readable, you can also combine named_scope finders to do complex finders.

by ihower
ihower
Fork me on GitHub