1

我定义了以下路线:

  resources :scenes do
    member do
      match 'files' => 'scenes#files', via: :get, as: 'scene_files'
    end
  end

我希望能够将嵌套路由称为scene_files_path,但 Rails 坚持scene要在路径中添加一个额外的,所以我最终得到的是scene_files_scene_path. 如何获得我正在寻找的命名路线?

4

1 回答 1

2

我开始简化您的成员块

resources :scenes do
  get :files, :as => :scene_files, :on => :member
end

然后我偶然发现

resources :scenes do
  get :files
end

产生:

> rake routes
  scene_files GET       /scenes/:scene_id/files(.:format)     scenes#files
       scenes GET       /scenes(.:format)                     scenes#index
             POST       /scenes(.:format)                     scenes#create
    new_scene GET       /scenes/new(.:format)                 scenes#new
   edit_scene GET       /scenes/:id/edit(.:format)            scenes#edit
        scene GET       /scenes/:id(.:format)                 scenes#show
              PUT       /scenes/:id(.:format)                 scenes#update
           DELETE       /scenes/:id(.:format)                 scenes#destroy

只有一个问题,参数键是:scene_idid

于 2012-08-18T04:12:30.017 回答