Check the contents of params with pry

background

When displaying the article details, I wanted to display the user name, but I did not know where it was stored, so I decided to examine the contents of params. Keep a log of the process.

manner

Install gem (gem'pry-rails') ↓ bundle install ↓ Enter binding.pry in the relevant part you want to check. ↓ rails s ↓ Click on the relevant part with your browser. The terminal shows the log that stopped at the point you entered. ↓ And [1] pry (# )> Is displayed, enter the character string you want to know there.

ruby:qiita.controller.rb



    12: def show
    13:   #I want to get only one post.
    14:   @post = Post.find(params[:id])
 => 15:   binding.pry
    16: end

Try from top to bottom id params[:id] @post.content @post.user I tried to enter!


[1] pry(#<PostsController>)> id
NameError: undefined local variable or method `id' for #<PostsController:0x00007f9f26ea4828>
from (pry):1:in `show'

[2] pry(#<PostsController>)> params[:id]
=> "1"

[3] pry(#<PostsController>)> @post.content
=> "Temporibus vel ratione aperiam alias aut libero reiciendis voluptatem quo autem rerum doloribus adipisci a voluptas modi illo qui ipsum aliquid voluptatum nventore at esse maiores ut omnis accusantium animi ducimus qui autem architecto excepturi itaque ex minus facere soluta inventore molestias id unde vero sunt aliquam quia dolorum quae placeat deserunt aspernatur qui suscipit quod dolorem maxime nulla id molestiae incidunt aut beatae aut voluptate aliquid dicta velit sit sint eum possimus nihil non voluptatem provident enim assumenda consequatur fugiat."

[4] pry(#<PostsController>)> @post.user
  User Load (0.2ms)  SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ?  [["id", 1], ["LIMIT", 1]]
  ↳ (pry):4:in `show'
=> #<User:0x00007f9f26c77b68
 id: 1,
 name: "swifty_kazu",
 email: "hogehogehoge",
 created_at: Fri, 16 Oct 2020 02:53:43 UTC +00:00,
 updated_at: Fri, 16 Oct 2020 02:53:43 UTC +00:00,
 password_digest: [FILTERED],
 admin: true>

[5] pry(#<PostsController>)> @post.user.name
=> "swifty_kazu"

[6] pry(#<PostsController>)> 

You can exit with exit!

Reference article https://qiita.com/tomoharutt/items/6b12af3dc5eb8dfb9801 https://pikawaka.com/rails/params#params%E3%81%AE%E4%B8%AD%E8%BA%AB%E3%82%92%E7%A2%BA%E8%AA%8D%E3%81%97%E3%81%A6%E3%81%BF%E3%82%88%E3%81%86 https://qiita.com/k0kubun/items/b118e9ccaef8707c4d9f

Recommended Posts

Check the contents of params with pry
[Rails] Check the contents of the object
Check the contents of the Java certificate store
Memo: [Java] Check the contents of the directory
Check the processing contents with [rails] binding.pry
Format the contents of LocalDate with DateTimeFormatter
Verify the contents of the argument object with Mockito
Overwrite the contents of config with Spring-boot + JUnit5
List the contents of categories created with Active Hash
Test the contents of an Excel file with JUnit
Check the behavior of Java Intrinsic Locks with bpftrace
Check the result of generic parameter inference with JShell
Check the operation of two roles with a chat application
Replace the contents of the Jar file
Check the version of Cent OS
Check the migration status of rails
[Ruby] Display the contents of variables
I tried to check the operation of gRPC server with grpcurl
How to check for the contents of a java fixed-length string
Check the operation using jetty with Maven.
The identity of params [: id] in rails
Folding and unfolding the contents of the Recyclerview
[Ruby] Cut off the contents of twitter-ads
About the treatment of BigDecimal (with reflection)
Check the version of the standard Web software.
[Java] Check the number of occurrences of characters
The contents of the data saved by CarrierWave.
Check the operation of the interface through threads
The problem that the contents of params are completely displayed in the [Rails] view
Check the domain by checking the MX record of the email address with java
[Ruby On Rails] How to search the contents of params using include?
[Java] Get MimeType from the contents of the file with Apathce Tika [Kotlin]
After all I wanted to preview the contents of mysql with Docker ...
Check the version of the JDK installed and the version of the JDK enabled
JAVA: jar, aar, view the contents of the file
Customize how to divide the contents of Recyclerview
Manage the version of Ruby itself with rbenv
The story of tuning android apps with libGDX
I want to var_dump the contents of the intent
Let's check the feel of Spring Boot + Swagger 2.0
Calculate the similarity score of strings with JAVA
Prepare the environment of CentOS 8 with Sakura VPS
Specify the default value with @Builder of Lombok
Measure the distance of the maze with breadth-first search
I checked the number of taxis with Ruby
I tried to check the operation of http request (Put) with Talented API Tester
[Docker] How to see the contents of Volumes. Start a container with root privileges.
[Swift] Get the number of steps with CMP edometer
CI the architecture of Java / Kotlin applications with ArchUnit
Check the capacity of the Linux server. (Df command, du command)
[Java] Check the JDK version of the built war file
[JUnit5] Dealing with "the reference of assertEquals is ambiguous"
Access the built-in h2db of spring boot with jdbcTemplate
The story of making a reverse proxy with ProxyServlet
Monitor the internal state of Java programs with Kubernetes
Implement the UICollectionView of iOS14 with the minimum required code.
[Rails] How to get the contents of strong parameters
Java: Use Stream to sort the contents of the collection
Roughly the flow of web application development with Rails.
Check the behavior of include, exclude, ExhaustedRetryException of Spring Retry
Check the rate limit application status of docker pull