A repository to hold all ruby, ruby on rails tips and tricks I find while studying!
For ruby basic tips, checkout ruby.md in this repository
$ rails new appName
$ rails new appName --database=postgresql
├── Gemfile
├── Gemfile.lock
├── README.rdoc
├── Rakefile
├── app
│ ├── assets
│ ├── controllers # Controller
│ ├── helpers
│ ├── mailers
│ ├── models # Model
│ └── views # View
├── bin
├── config
├── config.ru
├── db
├── lib
├── log
├── public
├── test
├── tmp
└── vendor
Inside /config/routes.rb
root 'static#top'
Use only to use specific action(s)
resources :books, only: [:index, :show]
Scope Routing Rules
get 'books/new' => 'books#new'
get 'books/edit/:id' => 'books#edit'
get 'books/undo/:id' => 'books#undo'
DRY 👇
scope controller: :books do
get 'books/new' => :new
get 'books/edit/:id' => :edit
get 'books/undo/:id' => :undo
end
DRY 👇
scope path: '/books', controller: :books do
get 'new' => :new
get 'edit/:id' => :edit
get 'undo/:id' => :undo
end
Even more syntactic
scope controller: :books do
👇
scope :books do
👇
controller :books do
scope path: '/books' do
scope '/books/' do
# nested implied prefixed paths
scope :books, :archived do
Will bundle module, name prefix, and path prefix settings into one declaration
namespace :admin do
resources :books
end
namespace :books, :controller => :books do
get 'new' => :new
get 'edit/:id' => :edit
post 'undo/:id' => :undo
end
If you want to add a namespace to controllers, categorize the files with folder
Add base controller for authentication
- ERB
- haml
- slim
- Sass
- Less
- coffee