ルートの代わりにUUIDを使用したいID標準ID。これは機能します:
# UUIDs are used for ids
UUID_regex = /([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/
resources :posts, :only => [:index, :show, :create], :constraints => {:id => UUID_regex}
つまり、Railsは問題なく受け入れ/posts/fb0f7c67-6f9b-4e2c-a26b-7700bb9b334d
ます。
しかし、私がこのようにそれらを入れ子にし始めると、
# UUIDs are used for ids
UUID_regex = /([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/
resources :posts, :only => [:index, :show, :create], :constraints => {:id => UUID_regex} do
resources :comments, :only => [:create, :destroy], :constraints => {:id => UUID_regex}
end
Railsは文句を言い始めます:No route matches [POST] "/post/fb0f7c67-6f9b-4e2c-a26b-7700bb9b334d/comments"
私は何が欠けていますか?
事前にThx。
注:私はRails3.2.2とruby1.9.3を使用しています。rake routes
は:
post_comments POST /posts/:post_id/comments(.:format) comments#create {:id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/, :post_id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/}
post_comment DELETE /posts/:post_id/comments/:id(.:format) comments#destroy {:id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/, :post_id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/}
posts GET /posts(.:format) posts#index {:id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/}
POST /posts(.:format) posts#create {:id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/}
post GET /posts/:id(.:format) posts#show {:id=>/([a-z0-9]){8}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){4}-([a-z0-9]){12}/}