ruby-on-rails – 使用复合键的Rails RESTful路由

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – 使用复合键的Rails RESTful路由前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个非典型的Rails应用程序,需要一个由两个值的复合键索引的表.使用RESTful服务添加两个值的复合键的正确方法是什么?

如果可能,请指出参考.

解决方法

我花了很多考验,提出了一个几乎“优雅”的解决方案:
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

猜你在找的Ruby相关文章