Rails Best Practices

1 votes

2 comments

2455 views

Name your model methods after their behavior, not implementation.

Business model methods should be named after the logic / business value they provide, not the implementation details. Violations to this practice tend to show up on ActiveRecord models.

by brasten
brasten

5 votes

7 comments

6636 views

Use cells to abstract view widgets

Rails developers always pay more attentions on models and controllers refactoring, they don't take care about views modularization, that makes view codes most difficult to maintain. Here I recommend you to use cells gem to write more reuseable, testable and cacheable view codes.

flyerhzm

3 votes

3 comments

4200 views

Optimize db migration

rails migration provides a convenient way to alter database structure, you can easily add, change and drop column to a existing table, but when the data in existing table are huge, it will take a long time to alter existing table, you should try to merge/optimize the db alter sql statements.

flyerhzm

10 votes

5 comments

4051 views

Restrict auto-generated routes.

By default, Rails generates seven RESTful routes(new,edit,create,destroy,index,show, update) for a resource, sometime the resource only needs one or two routes, so just user :only or :except while defining routes to speedup the routing.

implemented
by yorzi
yorzi

2 votes

5 comments

3562 views

Remove tab

Using tabs can mess up the spacing since some IDE's use 4 spaces for a tab, while others use 2, and some people don't use tabs at all, a mix of tabs and spaces causes things to not line up in most cases.

implemented
flyerhzm

5 votes

2 comments

4602 views

Active Record Query Interface Optimization

Use select with has_many and belongs_to on Active Record Associations

angelo capilleri

-4 votes

5 comments

4363 views

Create base conroller

Have base controllers for DRY

by guolei
guolei

11 votes

14 comments

4263 views

Keep code struture in models consistent

When the business logic of models becomes complex, it's very helpful to keep a consistent code structure that is agreed by team members.

by guolei
guolei

0 votes

1 comments

4172 views

Namespaced models

Make the app/models more clear using namespaced models

by guolei
guolei

20 votes

6 comments

7820 views

split route namespaces into different files

the routes will become complicated with the growth of your application, contain different namespaces, each with a lot of resources and custom routes, it would be better to split routes into different files according to the namespaces, which makes it easy to maintain the complicated routes.

flyerhzm
Fork me on GitHub