Rails Best Practices

-3 votes

11567 views

Create base conroller

Have base controllers for DRY

Comments

by guolei
guolei

16 votes

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

Comments

by guolei
guolei

1 votes

15855 views

Namespaced models

Make the app/models more clear using namespaced models

Comments

by guolei
guolei

32 votes

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

Comments

flyerhzm

13 votes

13559 views

Remove empty helpers

If you use rails generator to create scaffolds or controllers, it will also create some helpers, most of the helpers are useless, just remove them.

implemented

Comments

flyerhzm

26 votes

27244 views

Annotate your models

Are you tired of going to schema.rb to find your table structures information? It would be better to list all the attributes of the model in the model itself.

Comments

flyerhzm

14 votes

6368 views

defer expensive job

If you want to process something expensive as part of a web request, it will delay the response. If the job is not critical, it's wiser to move the expensive to a background queue and returns the response immediately.

Comments

flyerhzm

1 votes

12363 views

comment your magic codes

Ruby/Rails provides a lot of magic codes, especially for metaprogramming, they are powerful, less codes to implement more functions, but they are not intuition, you should write good comment for your magic codes.

Comments

flyerhzm

9 votes

17221 views

Simplify render in controllers

Like the simplify render in views, from rails 2.3, we can also simplify render in controllers.

implemented

Comments

flyerhzm

15 votes

34761 views

Simplify render in views

render is one of the often used view helpers, we can pass object, collection or local variables. From rails 2.3, more simplified syntax for render are provided.

implemented

Comments

flyerhzm