Skip to content

Instantly share code, notes, and snippets.

@arslanaly47
Created September 22, 2017 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arslanaly47/3500f55b17aa3db1599c0501b9a739fd to your computer and use it in GitHub Desktop.
Save arslanaly47/3500f55b17aa3db1599c0501b9a739fd to your computer and use it in GitHub Desktop.
Rules to follow for Ruby on Rails development
Followings are the basic rules to follow while building for Rails platform.
1) Write the logic in appropriate component, and avoid creating god classes: classes with more than 100 lines of code.
2) Write the database related stuff in model, and view related stuff in views. Controllers' job should be to connect both.
3) If a model has too much functionality, create multiple modules, and include them inside a model, instead of filling the model with all the functionalty.
4) Try to keep the controllers skinny.
5) Write funtionality that is portable across Web components as well as API components.
6) Make sure that the routes are following the RESTful schema. Avoid having the words like CREATE, UPDATE, DESTROY in the routes. Use HTTP Verbs for these purposes. For more info: https://code.tutsplus.com/tutorials/a-beginners-guide-to-http-and-rest--net-16340
7) Use the methods provided by Rails whereever it's possible. Avoid repeating too much code.
8) Use whitelisting the params, instead of manually assigning the params values.
9) Create a separate branch whenever you are going to start a task, and its name should be meaningful.
10) Try to name the variables according to Ruby conventions. Whenever one names varialbes or methods, it should always be connected with _(underscore). Use camel case when you are defining a class or a module. Use snake case else where in the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment