Rails: 7 basic actions defined on the controller

At first

** Day 16 of Calendar Planning 2020 ** It's been about 3 months since I started studying programming, so I will leave a note of what I learned in the article as an output. I would be happy if I could help anyone entering the world of programming. Please let me know if there are any words that are wrong, wrong, or misunderstood ^^ I'm sorry if it's hard to read the words for a long time. I will do my best to get used to it little by little.

Let's summarize the seven actions of rails

There are seven basic actions used in rails Controller. (As an exception, you may make your own name.) In principle, the names to be given when you want to play the seven roles introduced below are defined. Please list!

Action name role
new Create new data
create Add data
index Display a list of data
show Display the contents of the data
edit Edit the data
update Update data
destroy Delete data

I think there are many ways to express words, so please make it easy for you to understand! (To the extent that the meaning does not change ...)

new

It has the role of ** creating a new **.

For example A place to write letters or upload photos to post something on SNS Where to write articles on a blog That is the new action!

create

It has the role of ** adding and registering data **.

For example Created with new action (continuation of the above example) There is a button like "Post", right? That is the create action!

It is not displayed anywhere just by writing. No one can see it. It's in a state where it doesn't remain! Only after creating it will it remain as data.

index

It has the role of ** list display **.

For example Many people's posts are lined up on SNS, right? That is the index action.

show

It has the role of ** displaying contents and details **.

For example If you click and tap what is displayed in the index, you can see all the contents, or the screen will be only that post, right? It's a show action.

edit

** Edit ** Has a role.

For example I made a mistake in what I posted! The information has been updated, so I want to change the posted content! You edit at that time, right?

The place to edit is the edit action.

With an action that is newly created where it is not new edit is an action to recreate something. (Similar to new.)

update

** Update ** has a role.

This is an image to save the edited contents. Use the create action to save the new. Use the update action to save the edit.

It may be easy to remember as a set.

update not only saves edit, but also updates other changes. Don't think of it as a set only with edit. (I wrote it, but ...)

It is an overwritten image! (I!!)

destroy

The role of ** delete **.

For example This is the action taken when deleting a post or deleting an account. Erase data from the database! (It seems to be a physical deletion.)

This is a digression There is also a logical deletion, and although it disappears on the screen, the data remains.

For example As an operation, I want to keep the history of ordering in the past. But the user wants to unsubscribe. It is used at such times. You can also process that data remains on the administrator's screen when you cannot log in from the user side (withdrawal). The action used at this time is update, not destroy! There seems to be a way to use update like this!

Finally

I've summarized it briefly, but it's just a basic action. In some cases, the index is displayed on the show screen. The above content is not absolute, but basically I will use it! It may be good to remember it with a feeling!

Recommended Posts

Rails: 7 basic actions defined on the controller
[rails] List of actions defined in Controller
Ruby on Rails basic learning ①
[Rails] Put together the same code with controller actions
Ruby on Rails Basic Memorandum
Basic knowledge of Ruby on Rails
Check the root on the Rails browser
[Ruby on Rails] model, controller terminal command
part of the syntax of ruby ​​on rails
[Rails] Use validation on a specific controller
[Ruby on Rails] Controller test with RSpec
Ruby on Rails controller create / delete command
[Ruby on Rails] Until the introduction of RSpec
When the Ruby on Rails terminal rolls back
Tailwind on Rails
Publish the app made with ruby on rails
Determine the current page with Ruby on Rails
Rails basic philosophy
About Rails controller
[Ruby on Rails Tutorial] Error in the test in Chapter 3
Limit files created with the rails g controller command
Docker the development environment of Ruby on Rails project
Run Ruby on Rails RSpec tests with GitHub Actions
[Ruby on Rails] How to change the column name
Read the Rails Guide (Overview of Action Controller) again
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
Challenge the settings for developing with vue.js on Rails 6
(Ruby on Rails6) Reflecting the posted content from the form
Try using the query attribute of Ruby on Rails
Launch Rails on EC2
Test run on rails
Deploy RAILS on EC2
Ruby on Rails Elementary
Ruby on Rails basics
Yay! I'm on Rails!
Try actions on GitHub [actions]
Ruby On Rails Association
What to do when Rails on Docker does not reflect controller changes in the browser
Master the [Rails] scope!
[Ruby on Rails] Only the user who posted can edit
[Rails] Put the same restrictions on multiple pieces of information
[Ruby on Rails] Quickly display the page title in the browser
Created the first LINEbot on AWS Cloud9 (Rails + Heroku deployment)
(Ruby on Rails6) Display of the database that got the id of the database
[Environment construction] Get the Ruby on Rails 6 development environment within 1 hour
Delete all the contents of the list page [Ruby on Rails]
A note about the seed function of Ruby on Rails
[Ruby on Rails] Automatically enter the address from the zip code
[Note] About the Fizz_Buzz problem (How Ruby on Rails works)
How to run React and Rails on the same server