问题
I posted this question before, but changed some variable names and realized my mistake too late, so this code is unaltered in any way.
Error:
Routing Error uninitialized constant Firefighters Rails.root:
/Users/Vladdy/Dropbox/dev/firestaff
Here's the relevant, erroring bit from routes.rb
:
# get '/firefighters/dashboard' => 'firefighters#dashboard'
namespace :firefighters do
get '/dashboard' => 'firefighters#dashboard' # Namely, this one.
get '/dashboard/:date' => 'firefighters#dashboard'
get '/account' => 'firefighters#account'
get '/edit' => 'firefighters#edit'
get '/approve' => 'firefighters#approve'
end
If I uncomment line 1, and comment get /dashboard
, the dashboard loads just fine through FirefightersController#dashboard
.
I painstakingly checked that all of my model names are singular: Accountant
, Engineer
, Firefighter
and all of my controllers are plural: AccountingController
, EngineeringController
, etc.
Here is the stack trace of the error: http://pastebin.com/NpvY2EYy
I hope this is enough information. Once again - SOS! I do no know how to diagnose this problem. If it matters, I'm using ruby 2.3.0 and rails 4.2.5
Thanks you!
回答1:
get '/firefighters/dashboard' => 'firefighters#dashboard'
Works because your controller is
class FirefightersController
end
These
namespace :firefighters do
get '/dashboard' => 'firefighters#dashboard' # Namely, this one.
get '/dashboard/:date' => 'firefighters#dashboard'
get '/account' => 'firefighters#account'
get '/edit' => 'firefighters#edit'
get '/approve' => 'firefighters#approve'
end
Don't work because rails is expecting a module so your controller should be
class Firefighters::FirefightersController
You could if you're only bothered about the url, not about the folder structure for your app do
scope '/firefighters' do
get '/dashboard' => 'firefighters#dashboard' # Namely, this one.
get '/dashboard/:date' => 'firefighters#dashboard'
get '/account' => 'firefighters#account'
get '/edit' => 'firefighters#edit'
get '/approve' => 'firefighters#approve'
end
In which case you could leave your controller as it is.
来源:https://stackoverflow.com/questions/35462137/uninitialized-constant-error-pertaining-to-rails-namespaces