27
21

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.

URL(path)の文字列から Routing パラメーターの Hash に変換する

Posted at

タイトルの通りです。一度調べて忘れたので、備忘録として。

Rails.application.routes.recognize_path "users/1"
=> {:controller=>"users", :action=>"show", :id=>"1"}

対応する Route が無いと ActionController::RoutingError が出ます。
なお、その逆の働きをするのは

Rails.application.routes.generate_extras({:controller=>"users", :action=>"show", :id=>"1"})
=> ["/users/1", []]

です。
対応する Route が無いとこちらは ActionController::UrlGenerationError が出ます。

これで安心して忘れられます。

27
21
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
27
21

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?