我有一个版本化的API,我使用devise进行身份验证,我在路由中添加了以下内容并在下面收到错误。
如何设计将常量解析为Api :: V1 :: User而不是ApiV1User?
devise_for :api_v1_users
错误讯息:
/Users/danielcrompton/.rvm/rubies/ruby-1.9.3-p448/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/bin/rake default
Testing started at 11:25 AM ...
/Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:230:in `block in constantize': uninitialized constant ApiV1User (NameError)
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:229:in `each'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-3.2.14/lib/active_support/inflector/methods.rb:229:in `constantize'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise.rb:285:in `get'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/mapping.rb:77:in `to'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/mapping.rb:72:in `modules'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/mapping.rb:89:in `routes'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/mapping.rb:156:in `default_used_route'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/mapping.rb:66:in `initialize'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise.rb:319:in `new'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise.rb:319:in `add_mapping'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/rails/routes.rb:210:in `block in devise_for'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/rails/routes.rb:209:in `each'
from /Users/danielcrompton/.rvm/gems/ruby-1.9.3-p448/gems/devise-3.1.0/lib/devise/rails/routes.rb:209:in `devise_for'
from /**removed**/config/routes.rb:5:in `block (3 levels) in <top (required)>'
...
答案 0 :(得分:2)
这样做:
devise_for :api_v1_users, class_name: 'Api::V1::User'