Rails tutorial (6th edition) Background operation of the posting function of the micro post

table of contents

  1. Create new account
  2. Login (including Friendly Forwarding and permanent login) (https://qiita.com/akarin0519/items/f241b9699e156741a8d1)
  3. Edit Profile (https://qiita.com/akarin0519/items/4b3c64f88aefcaeb1781)
  4. Reset Password (https://qiita.com/akarin0519/items/ea873bb165ed4099a40e)
  5. ** Posting a micro post **
  6. Follow and unfollow

5. Posting a micro post

Operation screen

Posting a micropost proceeds in the following two steps.

  1. Log in to display the home screen. A micropost posting form is installed on the logged-in home screen.
  2. Enter the contents of the micropost and press the send button to save the contents of the micropost in the DB.

Background operation

The background operation executed in each of the above steps is as follows.

  1. See __ here __ for background behavior when logging in. Sending a GET request to/static_pages/home executes the home action of the StaticPages controller. In this home action, a new @ micropost is created in the form of being linked to the user ID (only the part related to the micropost is extracted). At the end of the home action, the corresponding view (/static_pages/home.html.erb) is called and the home screen is displayed. The @ micropost created by the home action is passed to this view, and Rails determines that it is a new micropost because the contents are empty.
  2. When the user fills out the micropost input form and presses the post button, a POST request to/microposts is sent and the Microposts controller create action is executed. Immediately before executing this create action, it is confirmed whether the user is currently logged in. In this create action, only the values ​​of params [: micropost] [: content] and params [: micropost] [: image] are allowed, stored in @ micropost, and tried to save to DB. .. If the save to DB is successful, the redirect to root_url will be performed and the home screen will be displayed.

Recommended Posts

Rails tutorial (6th edition) Background operation of the posting function of the micro post
Rails tutorial (6th edition) Background operation of login function
Rails tutorial (6th edition) Background operation of password reset function
Rails Tutorial (6th Edition) -Explanation of background operation for each function-
Rails tutorial (6th edition) Background operation of profile editing
Rails tutorial (6th edition) Follow/unfollow background operation
Rails Tutorial (4th Edition) Summary
[Rails] Implementation of tutorial function
Rails Tutorial (4th Edition) Memo Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 10
Rails Tutorial 6th Edition Learning Summary Chapter 4
Rails Tutorial 6th Edition Learning Summary Chapter 9
Rails Tutorial 6th Edition Learning Summary Chapter 6
Rails Tutorial 6th Edition Learning Summary Chapter 5
Rails Tutorial 6th Edition Learning Summary Chapter 2
Rails Tutorial 6th Edition Learning Summary Chapter 3
Rails Tutorial 6th Edition Learning Summary Chapter 8
I got an "ActionView :: Template :: Error: Permission denied" error in the test of 3.3.1 of Rails tutorial 6th edition, so I solved it.
[Ruby on Rails] Asynchronous communication of posting function, ajax
Implementation of Ruby on Rails login function (devise edition)
Rails Tutorial 4th Edition: Chapter 1 From Zero to Deployment
A note about the seed function of Ruby on Rails
[For beginners] Build the environment for Ruby on Rails Tutorial 4th Edition (Rails 5.1) in less than an hour!
[Rails 6] Implementation of search function
[Rails] Implementation of category function
Rails ~ Understanding the message function ~
[Rails] Implement image posting function
[Rails] Implementation of like function
[Ruby on Rails] Posting function that only logged-in users can post
I made a reply function for the Rails Tutorial extension (Part 5):