ruby-on-rails – 设计ensure_authentication_token报告未定义的
发布时间:2020-12-16 19:09:26 所属栏目:百科 来源:网络整理
导读:用户模型看起来像这样: before_save :ensure_authentication_tokendevise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable :token_authenticatableattr_accessible :email,:password,:password_confirmation,
用户模型看起来像这样:
before_save :ensure_authentication_token devise :database_authenticatable,:registerable,:recoverable,:rememberable,:trackable,:validatable :token_authenticatable attr_accessible :email,:password,:password_confirmation,:remember_me,:first_name,:last_name,:cell_phone,:city,:state,:country,:user_type 在devise.rb文件中我没有注释: config.token_authentication_key = :auth_token 我的用户迁移如下: class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable t.token_authenticatable t.timestamps end add_index :users,:email,:unique => true add_index :users,:reset_password_token,:authentication_token,:unique => true end def self.down drop_table :users end end 在创建用户时,会出现以下参数 {"utf8"=>"?","authenticity_token"=>"+F8cjCoauVKhZPSJLhW+AAhui1DygBcODsYn4Va/ktY=","user"=>{"first_name"=>"any_name","last_name"=>"any_name","email"=>"any_email@gmail.com","password"=>"[FILTERED]","password_confirmation"=>"[FILTERED]","cell_phone"=>"any_number","city"=>"some_city","state"=>"some_state","country"=>"U.S.A","user_type"=>"student"},"commit"=>"Sign up"} 但是在创建用户时仍然会出现以下错误: NameError in Devise::RegistrationsController#create undefined local variable or method `ensure_authentication_token' for #<User:0x007fd4448f7350> 我在这里做错了什么? 附:在我的Gemfile中,Devise gem的配置如下: gem 'devise',:git => 'git://github.com/plataformatec/devise.git',:branch => 'master' 解决方法
对不起,这是我的坏,我错过了一个逗号:)
devise :database_authenticatable,:validatable,#here :token_authenticatable 它现在正在工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |