1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

paramsに関するメモ

1
Posted at

ルーター

TechReviewSite::Application.routes.draw do
  root 'top#index'
  get 'products/:id' => 'products#show'
end

ターミナル

[1] pry(#<ProductsController>)> params
=> {"controller"=>"products", "action"=>"show", "id"=>"1"}
[2] pry(#<ProductsController>)> params.permit(:id)
=> {"id"=>"1"}
[3] pry(#<ProductsController>)> params[:id]
=> "1"
[4] pry(#<ProductsController>)> Product.find(params[:id])

products/:idは表示されているidを取ってくるのでbinding.pryをしたあとparamsと入力するとidの値をとることができる。params[:id]とするとvalueの1だけをとることができる

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?