1

我有一个名为views/admin/slinky_files/new.html.erb我正在尝试使用以下链接打开的视图:

<%= link_to 'Add New Slinky', new_slinky_file_path %>

当我单击链接时,这给了我一个错误:

Routing Error
uninitialized constant SlinkyFilesController

当然,这是因为它应该是Admin::SlinkyFilesController

我该如何解决?我不知何故需要路由new_slinky_file_path到而不是像admin_new_slinky_file_path我想的那样?

rake routes | grep slinky输出:

              slinkys GET    /slinkys(.:format)                            slinkys#index
                      POST   /slinkys(.:format)                            slinkys#create
           new_slinky GET    /slinkys/new(.:format)                        slinkys#new
          edit_slinky GET    /slinkys/:id/edit(.:format)                   slinkys#edit
               slinky GET    /slinkys/:id(.:format)                        slinkys#show
                      PUT    /slinkys/:id(.:format)                        slinkys#update
                      DELETE /slinkys/:id(.:format)                        slinkys#destroy
         slinky_files GET    /slinky_files(.:format)                       slinky_files#index
                      POST   /slinky_files(.:format)                       slinky_files#create
      new_slinky_file GET    /slinky_files/new(.:format)                   slinky_files#new
     edit_slinky_file GET    /slinky_files/:id/edit(.:format)              slinky_files#edit
          slinky_file GET    /slinky_files/:id(.:format)                   slinky_files#show
                      PUT    /slinky_files/:id(.:format)                   slinky_files#update
                      DELETE /slinky_files/:id(.:format)                   slinky_files#destroy
        admin_slinkys GET    /admin/slinkys(.:format)                      admin/slinkys#index
                      POST   /admin/slinkys(.:format)                      admin/slinkys#create
     new_admin_slinky GET    /admin/slinkys/new(.:format)                  admin/slinkys#new
    edit_admin_slinky GET    /admin/slinkys/:id/edit(.:format)             admin/slinkys#edit
         admin_slinky GET    /admin/slinkys/:id(.:format)                  admin/slinkys#show
                      PUT    /admin/slinkys/:id(.:format)                  admin/slinkys#update
                      DELETE /admin/slinkys/:id(.:format)                  admin/slinkys#destroy
4

1 回答 1

1

模板:

<%= link_to 'Add New Slinky', new_admin_slinky_file_url %>

控制器:

class Admin::SlinkyFilesController < ApplicationController
  def new
    @slinky_file = SlinkyFile.new
  end
end

路线.rb:

scope "admin" do
  resources :silky_files
end
于 2013-04-14T18:26:17.187 回答