22 Jul 2010
Wen-Tien Chang
According to Roy Fielding’s doctoral thesis, we should use restful routes to represent the resource and its state. Use the default 7 actions without overusing route customizations.
Read More
Tags
rails2
route
22 Jul 2010
Wen-Tien Chang
If you use RESTful design, you should NOT use default route. It will cause a security problem. I explain at http://ihower.tw/blog/archives/3265 too.
Read More
Tags
rails2
route
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
Some people will define 3 or more level nested routes, it's a kind of over design and not recommended.
Read More
Tags
rails2
route
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