Where I was interested in Progate's Ruby on Rails course [params]

I'm a beginner with no programming experience, but I finished Progate's Ruby on Rails course a while back.

When I reviewed it while doing the Rails tutorial, it didn't come out very well when I was doing Progate, but now that I can understand a little more, I would like to summarize what I noticed. I hope it will be useful for those who are progate but have not come to the point and think that they do not understand here.

What are params [Course III]

It's params that appears frequently in the Rails course, but honestly, I thought "I understand, I don't understand ...".

To put it plainly params is a method to get the value sent from the URL or the value entered in the form with params [: parameter name].

2020/6/20 I will add the URL of the page that I referred to very much https://note.com/sakusaku34/n/nc143e418b700

For example, in the case of the detail page of the posted content, it will be used like this.

def show
  @post = Post.find_by(id: params[:id])
end

In my case, I understand that each piece of knowledge is being said at that time, but since the knowledge was not connected when I wrote it, I try to break it down into elements as much as possible. The code in the example looks like this.

As a premise, these children are called actions.

The method defined by controller is called an action.

Citation & reference article https://qiita.com/morikuma709/items/5b21e9853c9d6ea70295

  1. First, @ post is a variable. First of all, this wasn't right! (Fatal)
  2. Define @post and look for the id in the Post table. Search by find_by [id: (id number)]. find_by [id: (id number)] can search the database for one element other than id. (user)
  3. This code specifies "find_by for id". From there, describe what id you want to find. In this case, params [: id] corresponds to that id. This params is a method to get the value sent from the URL or the value entered in the form with params [: parameter name]. (I wrote it twice because it's important)
  4. In other words, the value is sent as id from somewhere and it is received. Where the id is sent from It comes from the routing of Posts with unique ids registered in the database.

This code means, "Since the database id of each post was set as the URL in the routing, usefind_by [id: (id number)]to find and display the one with the same id number." ..

Summary

-Params is a method to get the value sent from the URL or the value entered in the form with params [: parameter name] -Find_by [id: (id number)] can search the database for one element other than id.

Since I am a beginner, there may be some parts that I am not aware of, but thank you for reading this far. I would appreciate it if you could comment on any corrections or correction points.

Recommended Posts

Where I was interested in Progate's Ruby on Rails course [params]
What I was interested in in Progate's Ruby on Rails course [Each statement of error message]
Ruby on Rails Japanese-English support i18n
I summarized the flow until implementing simple_calendar in Ruby on Rails.
Ruby on Rails in Visual Studio Codespaces
Beginners create portfolio in Ruby on Rails
Where I got stuck in today's "rails tutorial" (2020/10/08)
Recommendation of Service class in Ruby on Rails
Rails new in Ruby on Rails ~ Memorandum until deployment 2
Where I got stuck in today's "rails tutorial" (2020/10/05)
Where I got stuck in today's "rails tutorial" (2020/10/06)
Rails new in Ruby on Rails ~ Memorandum until deployment 1
Where I got stuck in today's "rails tutorial" (2020/10/04)
(Ruby on Rails6) Creating data in a table
[Ruby on Rails] How to install Bootstrap in Rails
Where I got stuck in today's "rails tutorial" (2020/10/07)
I made a portfolio with Ruby On Rails
I understand Ruby on Rails params (with Hanshin Tigers poker faceman, Atsushi Nomi)
[Ruby on Rails] How to write enum in Japanese
[Ruby on Rails Tutorial] Error in the test in Chapter 3
I can't overwrite information on columns in rails console ...
[Ruby] I can't install puma on Mac [Rails, etc.]
[Ruby On Rails] How to reset DB in Heroku
Ruby on Rails Elementary
Ruby on Rails basics
[Ruby on Rails] Post image preview function in refile
Ruby On Rails Association
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
[Ruby on Rails] credential does not work in production environment even though I saved production.key
I tried installing Ruby on Rails related plugin with vim-plug
Difficulties in building a Ruby on Rails environment (Windows 10) (SQLite3)
Definitely useful! Debug code for development in Ruby on Rails
What I was addicted to while using rspec on rails
[Ruby on Rails] Quickly display the page title in the browser
A story I was addicted to in Rails validation settings
[Apple login] Sign in with Apple implementation procedure (Ruby on Rails)
How to display a graph in Ruby on Rails (LazyHighChart)
Apply CSS to a specific View in Ruby on Rails
Beginner Ruby on Rails What I learned is being summarized
Portfolio creation Ruby on Rails
Ruby on rails learning record -2020.10.04
[Ruby on Rails] Debug (binding.pry)
Ruby on rails learning record -2020.10.05
Ruby on rails learning record -2020.10.09
Ruby on Rails config configuration
Ruby on Rails basic learning ①
[Ruby on Rails] about has_secure_password
Ruby on rails learning record-2020.10.07 ②
Commentary on partial! --Ruby on Rails
Ruby on rails learning record-2020.10.07 ①
Cancel Ruby on Rails migration
Ruby on rails learning record -2020.10.06
Ruby on Rails validation summary
Ruby on Rails Basic Memorandum
I want to add a browsing function with ruby on rails
Build a development environment where Ruby on Rails breakpoints work on Windows
(Ruby on Rails6) Creating a database and displaying it in a view
Erase N + 1 in acts_as_tree of tree structure Gem of Ruby on Rails
Things to remember and concepts in the Ruby on Rails tutorial
Ruby on Rails Overview (Beginner Summary)
[Ruby on Rails] Read try (: [],: key)