CRUD Basics
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]
Published on 30 Mar 2020
all tags
100daysofcode activerecord android annoyances api apt arch array artix atom az3w backend bash blog browser bug callback career ci-cd cli cloud code coding config configuration cp crud cryptography css csv database db design devops django docker email erp feelsgood filter fugitive gif gist git gnome gnome pomodoro grep hebrew http ide isbn-fetcher iso javascript job search js kanban kindle koans learning linkedin linux logger manjaro map markdown microservices mobi mtp neovim nodejs nvchad packages panda pastbin patch portfolio post postgres pytest python rails reduce refactoring reflections rest routes rspec ruby salesforce script scripting security sed shell sql string_replacement study tdd terminal testing tmux ttd version_control vim vim sort walkthrough webdev workflow zsh