2

我有一个非常基本的问题,正在查看一些类似于以下但无法解释的 Rails 代码,从中推断出的 REST url 和相应的操作是什么?有人可以帮助理解,因为我没有找到任何类似路线的例子。

map.resources :myresources do |item|
    item.resources :v, :controller => 'my_controller' do |v|
      v.resource :abc
    end
end

提前致谢!!

4

1 回答 1

0

这实际上是旧的路由样式。现在您可以这样编写代码:

resources :myresources do
  resources :v, :controller => "my_controller" do
    resource :abc
  end
end

使用此代码,您将获得以下路线:

     myresource_v_abc POST   /myresources/:myresource_id/v/:v_id/abc(.:format)      abcs#create
 new_myresource_v_abc GET    /myresources/:myresource_id/v/:v_id/abc/new(.:format)  abcs#new
edit_myresource_v_abc GET    /myresources/:myresource_id/v/:v_id/abc/edit(.:format) abcs#edit
                      GET    /myresources/:myresource_id/v/:v_id/abc(.:format)      abcs#show
                      PUT    /myresources/:myresource_id/v/:v_id/abc(.:format)      abcs#update
                      DELETE /myresources/:myresource_id/v/:v_id/abc(.:format)      abcs#destroy
   myresource_v_index GET    /myresources/:myresource_id/v(.:format)                my_controller#index
                      POST   /myresources/:myresource_id/v(.:format)                my_controller#create
     new_myresource_v GET    /myresources/:myresource_id/v/new(.:format)            my_controller#new
    edit_myresource_v GET    /myresources/:myresource_id/v/:id/edit(.:format)       my_controller#edit
         myresource_v GET    /myresources/:myresource_id/v/:id(.:format)            my_controller#show
                      PUT    /myresources/:myresource_id/v/:id(.:format)            my_controller#update
                      DELETE /myresources/:myresource_id/v/:id(.:format)            my_controller#destroy
          myresources GET    /myresources(.:format)                                 myresources#index
                      POST   /myresources(.:format)                                 myresources#create
       new_myresource GET    /myresources/new(.:format)                             myresources#new
      edit_myresource GET    /myresources/:id/edit(.:format)                        myresources#edit
           myresource GET    /myresources/:id(.:format)                             myresources#show
                      PUT    /myresources/:id(.:format)                             myresources#update
                      DELETE /myresources/:id(.:format)                             myresources#destroy
于 2012-11-12T13:49:39.563 回答