I want to know the content value contained in @item
items#show
def show
@item = Item.find(params[:id])
end
#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
def show
@item = Item.find(params[:id])
binding.pry
end
Stopping processing when the show action is executed by binding.pry
Actually open the browser and execute the show action that opens the page of show.hrml.erb.
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 (#
[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