1
0

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 1 year has passed since last update.

[Rails] ActionPack の routing と args のメモ

Last updated at Posted at 2022-03-10

SEO対策タスクでルーティング、リダイレクト周りを色々触っている。
この時使ったテクニックのメモ。
(追記)それぞれで別の記事にするべきだった気がしてきた

pathから対応Controller#Action求める

> Rails.application.routes.recognize_path("https://www.jobs.com/companies/1")
=> {:controller=>"companies", :action=>"show", :id=>"1"}

コントローラ内のargs

  • クエリパラメータで指定されたparamsの一覧 -> request.query_parameters
  • URLパスで指定されたparamsの一覧 -> request.path_parameters

rails console で、pathを確認する

> Rails.application.routes.url_helpers.companies_path
=> "/companies"
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?