Rule |
Class name |
Filename |
All models are singular |
Note |
note.rb |
All controllers are plural |
Notes |
notes_controller.rb |
View folder names are plural |
- |
notes/index.html.haml |
rails new <project-name> # create a new project
rails generate model <model_name_singular> <optional-fields>:<field-type>
rails generate controller <controller_name_plural> <optional-methods>
rails generate migration <migration-name> <optional-fields>
Ex: rails g migration AddNameToUser name:string
rake db:migrate # to migrate db
rake db:rollback # to rollback
- :primary_key
- :string, :text
- :integer, :float, :decimal
- :datetime, :time, :date
- :binary, :boolean.
config file - config/routes.rb
root to: "controller#action"
resources :<controller_name_plural>
eg: resources :notes
resource :<controller_name_singular>
eg: resource :session, only: [:create, :destroy]
Path: lib/tasks
<task_name>.rake
lib/tasks // Path to rake tasks
$ rake -T // To list all rake tasks
$ rake db:seed // To seed data to db, lives in db/seeds.rb
Path: spec/models, spec/conntroller
spec file should end with _spec.rb
Eg: notes_controller_spec.rb
$ rails generate rspec:install
$ rails g rspec:model <model_name>
$ rails g rspec:controller <controller_name>