使用rails 4.2.1,Ruby 2.1.1,Devise 3.5.2创建一个Rails后端,为未来的Android应用程序进行身份验证,允许用户注册登录/注销JSON请求,生成android应用程序的令牌将消耗。
当我输入rake db:create db:migrate
我收到以下错误:
NoMethodError: undefined method `token_authentication_key=' for Devise:Module
我更新设计的唯一文件如下:
## Token authenticatable
t.string :authentication_token
add_index :users, :authentication_token, :unique => true
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:token_authenticatable
before_save :ensure_authentication_token
end
def skip_confirmation!
self.confirmed_at = Time.now
end
# ==> Configuration for :token_authenticatable
# Defines name of the authentication token params key
config.token_authentication_key = :auth_token
t.string :name, :null => false, :default => ""
## Confirmable
t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
add_index :users, :confirmation_token, :unique => true
** Invoke db:create (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:create
db/development.sqlite3 already exists
db/test.sqlite3 already exists
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
rake aborted!
NoMethodError: undefined method `token_authentication_key=' for Devise:Module
/home/pc/layer_1/config/initializers/devise.rb:14:in `block in <top (required)>'
/home/pc/.rvm/gems/ruby-2.2.1/gems/devise-3.5.2/lib/devise.rb:278:in `setup'
/home/pc/layer_1/config/initializers/devise.rb:3:in `<top (required)>'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `block in load'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in `load'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/engine.rb:652:in `block in load_config_initializer'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/notifications.rb:166:in `instrument'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/engine.rb:651:in `load_config_initializer'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/engine.rb:615:in `each'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/engine.rb:615:in `block in <class:Engine>'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `instance_exec'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/initializable.rb:30:in `run'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:226:in `block in tsort_each'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:420:in `block (2 levels) in each_strongly_connected_component_from'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:429:in `each_strongly_connected_component_from'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:419:in `block in each_strongly_connected_component_from'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `each'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/initializable.rb:44:in `tsort_each_child'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in `call'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:413:in `each_strongly_connected_component_from'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:347:in `block in each_strongly_connected_component'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `call'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:345:in `each_strongly_connected_component'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:224:in `tsort_each'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/tsort.rb:203:in `tsort_each'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/initializable.rb:54:in `run_initializers'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/application.rb:352:in `initialize!'
/home/pc/layer_1/config/environment.rb:5:in `<top (required)>'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `block in require'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in `load_dependency'
/home/pc/.rvm/gems/ruby-2.2.1/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in `require'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/application.rb:328:in `require_environment!'
/home/pc/.rvm/gems/ruby-2.2.1/gems/railties-4.2.1/lib/rails/application.rb:457:in `block in run_tasks_blocks'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `call'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:240:in `block in execute'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `each'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:235:in `execute'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:179:in `block in invoke_with_call_chain'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:201:in `block in invoke_prerequisites'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `each'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:199:in `invoke_prerequisites'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:178:in `block in invoke_with_call_chain'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/monitor.rb:211:in `mon_synchronize'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:172:in `invoke_with_call_chain'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/task.rb:165:in `invoke'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:150:in `invoke_task'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block (2 levels) in top_level'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `each'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:106:in `block in top_level'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:115:in `run_with_threads'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:100:in `top_level'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:78:in `block in run'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:176:in `standard_exception_handling'
/home/pc/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/rake/application.rb:75:in `run'
/home/pc/.rvm/rubies/ruby-2.2.1/bin/rake:33:in `<main>'
Tasks: TOP => db:migrate => environment
对于长跟踪命令调用很抱歉,非常感谢任何帮助。
答案 0 :(得分:6)
从版本3.2或其他东西开始,对于安全问题,Devise不再具有token_authentication系统。请参阅:https://github.com/plataformatec/devise/issues/2739
看起来你有一个旧版装备的初始化器。
您可以使用其他方式为Android应用程序进行身份验证,或者使用额外的gem来重新设置token_authentication系统。例如https://github.com/baschtl/devise-token_authenticatable。