CRUD Basics
Published on 30 Mar 2020
HTTP Verbs
VERB | Usage | Multiple Requests | Cache / Bookmark |
---|---|---|---|
GET | links | yes | yes |
POST | forms | no | no |
PATCH | forms | yes | no |
DELETE | forms | yes | no |
Standard CRUD Actions in Rails
CRUD | Action | Description | Example URL | HTTP Verb |
---|---|---|---|---|
READ | index | List records | /subjects | GET |
READ | show | Display a single record | /subjects/show/:id | GET |
CREATE | new | Display new record form | /subjects/new | GET |
CREATE | create | Process new record form | /subjects/create | POST |
UPDATE | edit | Display an edit record form | /subjects/edit/:id | GET |
UPDATE | update | Process edit record form | /subjects/update/:id | PATCH/PUT |
DELETE | delete | Display delete record form | /subjects/delete/:id | GET |
DELETE | destroy | Process delete record form | /subjects/destroy/:id | DELETE |
Useful resource: https://guides.rubyonrails.org/routing.html#crud-verbs-and-actions
Default Resourceful Routes
# config/routes.rb
# Provides `index`, `show`, `new`, `create`, `update`
resources :subjects
# Provides the above and `delete`.
resources :subjects do
# operates on an existing member of the resource,
# i.e. expect to receive a member :id in the URL
member do
get :delete
end
# DOES NOT operate on an existing member
# i.e. DOES NOT expect to receive a member :id in the url
controller do
get :export
end
end
# Provides `index`, `new`, `create`, `update` BUT NOT `show`
resources :admin_users, except: [:show]
# Provides `index` and `show` ONLY
resources :products, only: [:index, :show]
all tags
activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career cli cloud code coding config configuration cp crud css database db design devops django email erp filter fugitive gif gist git gnome grep hebrew http ide isbn-fetcher iso javascript job search js kanban kanban\ kindle koans linux logger manjaro map markdown microservices mobi mtp neovim nodejs packages pastbin patch post python rails reduce refactoring rest routes rspec ruby scripting security sed shell sql string_replacement study tdd terminal testing version_control vim walkthrough workflow