6
6

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.

Rails でリソース ID にドットを含めつつフォーマットを指定する

Posted at

地味にハマったのでメモ。

Rails でリソース ID にドットを含めたい場合、

routes.rb
resources :users, id: %r{[^/]+} do
  ...
end

と書くと、フォーマットも ID に含まれてしまう。
例えば、/users/bob.dylan.json にアクセスすると、id: bob.dylan.json, format: html なんてことになる。

これを回避するには、以下のように書けば良かった。

routes.rb
resources :users, id: %r{[^/]+?}, format: /json|csv|xml|html/ do
  ...
end
6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?