Skip to content

Instantly share code, notes, and snippets.

@unmultimedio
Last active September 15, 2020 03:59
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 unmultimedio/375d4acc52ae9877ee2f457b7efbd341 to your computer and use it in GitHub Desktop.
Save unmultimedio/375d4acc52ae9877ee2f457b7efbd341 to your computer and use it in GitHub Desktop.
Ruby on Rails Objects Naming Convention for each layer on the framework

Rails Objects Naming Convention

CoC in RoR is awesome, nevertheless, when starting in the framework, getting to know by memory the convention is quite hard, so here's a cheat sheet of how to name a model on each layer of a standard MVC app:

Layer Plural or Singular Files / Folders Names
Database plural N/A snake_case table names: users, todos, todo_items, organization_members, payment_confirmations
Model singular snake_case files names: user.rb, todo.rb, todo_item.rb, organization_member.rb, payment_confirmation.rb PascalCase classes names: User, Todo, TodoItem, OrganizationMember, PaymentConfirmation
Controller plural snake_case files names: users_controller.rb, todos_controller.rb, todo_items_controller.rb, organization_members_controller.rb, payment_confirmations_controller.rb PascalCase classes names: UsersController, TodosController, TodoItemsController, OrganizationMembersController, PaymentConfirmationsController
View plural snake_case folders names: users, todos, todo_items, organization_members, payment_confirmations (and within each folder, the regular views index, new, edit) N/A

Hope it helps to anyone learning RoR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment