[RUBY] Check the processing contents with [rails] binding.pry

Thing you want to do

I want to know the content value contained in @item

  def show
    @item = Item.find(params[:id])
#show.html.Description of erb
<%= link_to 'Go to the purchase screen',item_orders_path(@item.id)%>

Processing content Click the "Proceed to purchase screen" button to switch to orders # index (/ items /: item_id / orders (.: Format)). When you press the purchase button, you will see the contents of @item, but I want to see what kind of information is extracted

How to check the processing contents

  1. Write ``` gem'pry-rails'` `` in Gemfile and install
  2. Write binding.pry in items # show
  def show
    @item = Item.find(params[:id])

Stopping processing when the show action is executed by binding.pry

  1. Actually open the browser and execute the show action that opens the page of show.hrml.erb.

  2. The process will stop, so look at the console server

app/controllers/items_controller.rb:41 ItemsController#show:
    40: def show
 => 41:   binding.pry
    42: end

[1] pry(#<ItemsController>)>

You can see that the process is stopped by the show action

5 [1] Write @item in pry (# )>

[1] pry(#<ItemsController>)> @item
=> #<Item:0x00007f9ac9e01300
 id: 8,
 item_name: "ramen",
 info: "It tastes good!",
 category_id: 3,
 status_id: 3,
 shipping_id: 3,
 area_id: 5,
 schedule_id: 4,
 price: 1000,
 user_id: 1,
 created_at: Fri, 04 Sep 2020 01:29:20 UTC +00:00,
 updated_at: Fri, 04 Sep 2020 01:29:20 UTC +00:00>

Now you know the value of the contents in @item!


[1] pry (# )> with @ item.id

[2] pry(#<ItemsController>)> @item.id
=> 8

It turns out that the content of @ item.id is "8"


<% = link_to'Proceed to purchase screen', item_orders_path (@ item.id)%> If you want to transition to item_orders_path, you cannot transition unless item_id is specified.

item_orders  /items/:item_id/orders(.:format)  orders#index
<%= link_to 'Go to the purchase screen',item_orders_path(@item.id)%>

By specifying (@ item.id) I was able to extract the necessary information for: item_id!

Recommended Posts

Check the processing contents with [rails] binding.pry
[Rails] Check the contents of the object
Check the contents of params with pry
Check the migration status of rails
Image processing: Let's play with the image
Check the root on the Rails browser
Check the operation using jetty with Maven.
Memo: [Java] Check the contents of the directory
Prepare the format environment with "Rails" (VScode)
Prepare the security check environment for Rails 6
Play with the Processing libraries "ControlP5", "Fisica"
Implement the box ball system with Processing
Format the contents of LocalDate with DateTimeFormatter
I rewrote the Rails tutorial test with RSpec
Add binding.pry (rails)
Use the Mac menu bar with Processing 3 apps
Publish the app made with ruby on rails
Overwrite the contents of config with Spring-boot + JUnit5
Implement the Like feature in Ajax with Rails.
Determine the current page with Ruby on Rails
Christmas with Processing
Try to summarize the common layout with rails
How to check Rails commands in the terminal
Now that you have deployed AWS with Rails On Docker, let's organize the contents.
How to make batch processing with Rails + Heroku configuration
List the contents of categories created with Active Hash
Limit files created with the rails g controller command
[Heroku] Associate AWS S3 with the deployed Rails app
[Rails] I tried playing with the comment send button
Test the contents of an Excel file with JUnit
Check the behavior of Java Intrinsic Locks with bpftrace
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
Challenge the settings for developing with vue.js on Rails 6
[Rails] How to get the contents of strong parameters
Check the result of generic parameter inference with JShell
Addicted to the webpacker that comes standard with Rails 6
Roughly the flow of web application development with Rails.
[Rails] Put together the same code with controller actions
Control the processing flow of Spring Batch with JavaConfig.
When the server does not start with rails s
Rails deploy with Docker
[Rails 6] RuntimeError with $ rails s
Handle devise with Rails
[Rails] Learning with Rails tutorial
[Rails] Test with RSpec
[Rails] Development with MySQL
Supports multilingualization with Rails!
Master the [Rails] scope!
Double polymorphic with Rails
[Rails] Processing after adding a column to the devise table
Why can I use the rails command installed with gem? ??
I tried to increase the processing speed with spiritual engineering
Check the operation of two roles with a chat application
Delete all the contents of the list page [Ruby on Rails]
[With back tricks] How to introduce React to the simplest Rails
[Rails] I tried to implement batch processing with Rake task
[Java] Check the difference between orElse and orElseGet with IntStream
Use your own classes in the lib directory with Rails6