解决方法
我花了很多考验,提出了一个几乎“优雅”的解决方案:
scope "/users/:key1/:key2" do resource :users,:path => "" do resources :posts end end
它产生:
users_posts GET /users/:key1/:key2/posts(.:format) posts#index POST /users/:key1/:key2/posts(.:format) posts#create new_users_post GET /users/:key1/:key2/posts/new(.:format) posts#new edit_users_post GET /users/:key1/:key2/posts/:id/edit(.:format) posts#edit users_post GET /users/:key1/:key2/posts/:id(.:format) posts#show PUT /users/:key1/:key2/posts/:id(.:format) posts#update DELETE /users/:key1/:key2/posts/:id(.:format) posts#destroy users POST /users/:key1/:key2(.:format) users#create new_users GET /users/:key1/:key2/new(.:format) users#new edit_users GET /users/:key1/:key2/edit(.:format) users#edit GET /users/:key1/:key2(.:format) users#show PUT /users/:key1/:key2(.:format) users#update DELETE /users/:key1/:key2(.:format) users#destroy