简体   繁体   中英

Rails routing a path

I have a view called views/admin/slinky_files/new.html.erb that I am trying to open with the following link:

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

And that gives me an error when i click on the link:

Routing Error
uninitialized constant SlinkyFilesController

And of course, this is because it should be Admin::SlinkyFilesController

How do I fix this? I somehow need to route the new_slinky_file_path to instead be something like admin_new_slinky_file_path I think?

rake routes | grep slinky rake routes | grep slinky OUTPUT:

              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

template:

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

contoller:

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

routes.rb:

scope "admin" do
  resources :silky_files
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM