Naming Convention in Ruby on Rails

Nick Frangione
2 min readApr 29, 2021

Ruby on Rails is a web application framework in Ruby programming language, which means that it provides developers tools to be able to more easily build out the base functionality of new applications.

A lot of web application frameworks, including Ruby on Rails, use a MVC (Model View Controller) Framework. To briefly touch on what this is, a Model View Controller architecture means that the application is broken down into three main logical components which will handle specific parts of the application: Model, View, & Controller.

Model:

The model is a Ruby class, with a corresponding database table, that will perform a number of tasks to work with the database, based on user input, and gives the desired data to the controller.

Naming Conventions:

  • Model Class names use CamelCase(ClassName) & are singular
  • Model Methods use snake_case(class_name)

EXP:

class Dog < ApplicationRecord

has_many :employees

def method_name

end

end

Controllers:

The controller acts as the middle-man between the model and the view. It creates instance variables of what to display within its methods, that will them be passed down to the view based on the user input.

Naming Conventions:

  • Controller Class names are written in CamelCase (ResourcesController) , but the resource is usually plural, and the Controller is singular.
  • The Controller Actions are written in snake_case, but are usually just the 7 Standard Routes Names: index, show, new, create, update, delete.

EXP:

class DogsController < ApplicationController

def index

end

def show

end

end

View:

The view handles the rendering of what the user wants to bring up on the page, which it has access to through the controller’s actions and their instance variables.

Naming Conventions:

  • The view directory has a directory inside it for each resource you are working with. These are named using snake_case and are plural (dogs).
  • This directory/folder will contain a controller_action_name.html.erb file for each controller_action (Often Just 7 Standard Route Names) within that directory’s controller.

EXP:

For More On Naming Conventions:

--

--