About params

This time I summarized params. Actually, the reason for summarizing this time was a question from a beginner, params. I ran away to params so I couldn't answer. I found out when I read the article on prams again this time, so I wrote it as a reference. I am also a beginner

params are for putting the information obtained by the link or input form into the method. This time I will go to my page.

show.html.erb


<a href = "users/current_user.id" class = "users">Yamada Taro</>
id name age
1 Yamada Taro 22

a.controller.rb


def show
  @user = User.find(params[:id])
  binding.pry
end
pry(#<InfomationsController>)> params
=> <ActionController::Parameters {"controller"=>"infomations", "action"=>"show", "id"=>"1"} permitted: false>

By doing this, the information of the current_user.id number is entered in @user by adding params to the id. On the contrary, if there are no params

a.controller.rb



def show
 @user = User.find(:id)

Couldn't find User with 'id'=id)

I get an error saying that the id cannot be recognized. So you should get the data using params except for the index method.

Recommended Posts

About params
About =
About method.invoke
About Kotlin
About attr_accessor
About Hinemos
About inheritance
About Docker
About Rails 6
About form_for
About Spring ③
About enum
About polymorphism
About Optional
About hashes
About JitPack
About Dockerfile
About this ()
About devise
About encapsulation
About Docker
About JAVA_HOME
About active_hash
About static
About exceptions
About scope
[Maven] About Maven
About exception handling
Review about bundler
About Java interface
About Rails routing
About exception handling
About AsyncTask Generics
About Ruby symbols
About array multiplication
[Java] About arrays
About HotSpot VM
About ruby ​​form
[Swift] About generics
About Active Storage
About class inheritance.
About Spring AOP
About Ruby Hashes
About singular methods
About getter setter
About build tools
About MacinCloud introduction
[Note] About nil
About keyword arguments
Chew about API
[About double hash]
About installing Cocoapods
Something about java
Where about java
About HttpServlet () methods
What is params
About Java features
About ActiveRecord :: PendingMigrationError
About SIGNING_REGION: NoSuchFieldError
About the method
About standard classes