18 Sep 2013
David Davis
The params hash contains all the data that was submitted from a request. If you modify it, later code won't have access to it. Instead, copy the params hash and modify the copy.
Read More
Tags
controller
params
02 Jun 2011
Guo Lei
Tags
controller
12 Dec 2010
Richard Huang
Like the simplify render in views, from rails 2.3, we can also simplify render in controllers.
Read More
Tags
controller
24 Jul 2010
Wen-Tien Chang
Don't repeat yourself in controller, use before_filter to avoid duplicated codes.
Read More
Tags
controller
24 Jul 2010
Wen-Tien Chang
According to MVC architecture, there should not be logic codes in view, in this practice, I will introduce you to move codes into controller.
Read More
Tags
controller
view
24 Jul 2010
Wen-Tien Chang
For CRUD resources, we always write the same 7 actions with duplicated codes. To avoid this, you can use inherited_resources plugin. But be careful, there is DRY controller debate!! (http://www.binarylogic.com/2009/10/06/discontinuing-resourcelogic/) 1. You lose intent and readability 2. Deviating from standards makes it harder to work with other programmers 3. Upgrading rails trouble
Read More
Tags
controller
plugin
23 Jul 2010
Wen-Tien Chang
named_scope is awesome, it makes your codes much more readable, you can also combine named_scope finders to do complex finders.
Read More
Tags
rails2
controller
model
22 Jul 2010
Wen-Tien Chang
Use accepts_nested_attributes_for to make nested model forms much easier, this feature is provided by rails 2.3
Read More
Tags
controller
model
view
22 Jul 2010
Wen-Tien Chang
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.
Read More
Tags
controller
model
view
21 Jul 2010
Wen-Tien Chang
Use model callback can avoid writing some logic codes in controller before or after creating, updating and destroying a model.
Read More
Tags
controller
model
21 Jul 2010
Wen-Tien Chang
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
Read More
Tags
controller
model
21 Jul 2010
Wen-Tien Chang
In MVC model, controller should be simple, the business logic is model's responsibility. So we should move logic from controller into the model.
Read More
Tags
controller
model
21 Jul 2010
Wen-Tien Chang
Do not assign the model's attributes directly in controller. Add model virtual attribute to move the assignment to model.
Read More
Tags
controller
model
20 Jul 2010
Wen-Tien Chang
You can use scope access to avoid checking the permission by comparing the owner of object with current_user in controller.
Read More
Tags
controller
19 Jul 2010
Wen-Tien Chang
Use model association to avoid assigning reference in controller.
Read More
Tags
controller
model
14 Jul 2010
Wen-Tien Chang
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.
Read More
Tags
rails2
controller
model