Rails Engineering References

Purpose

Quick-reference material for Rails development.

These references are intended for lookup rather than learning. For in-depth explanations, see the referenced guides and handbooks.

Rails Conventions

ConceptConventionExample
ModelSingular, CamelCaseUserAccount
TablePlural, snake_caseuser_accounts
ControllerPlural, CamelCase with ControllerUserAccountsController
RouteResourceful, snake_caseresources :users
MigrationDescriptive snake_caseadd_email_to_users
ServiceNamed after operationRegisterUser

Common Generators

CommandCreates
rails generate model User email:stringModel, migration, factory
rails generate controller Api::V1::UsersController, routes, specs
rails generate migration add_email_to_usersMigration file
rails generate resource Product name:stringModel, controller, routes,
migration, factory

Testing Commands

CommandPurpose
bundle exec rspecRun full test suite.
bundle exec rspec spec*models*Run model specs.
bundle exec rspec spec*requests*Run request specs.
bundle exec rspec spec*system*Run system specs.
bundle exec rspec spec*models*user_spec.rb:5Run a single test by line.

Key Gems

GemPurpose
DeviseAuthentication
PunditAuthorization
RSpec-RailsTesting framework
FactoryBotTest data factories
SidekiqBackground job processing
BulletN+1 query detection
RuboCopStyle linting
Rack::AttackRate limiting

Rails Error Codes

HTTP CodeRails HelperWhen to Use
200:okSuccessful GET request.
201:createdSuccessful POST (resource
created).
204:no_contentSuccessful DELETE or PUT with
no response body.
400:bad_requestMalformed request parameters.
401:unauthorizedAuthentication required.
403:forbiddenAuthenticated but not
authorized.
404:not_foundResource does not exist.
422:unprocessable_entityValidation failure.
429:too_many_requestsRate limit exceeded.

Related Documents