[英]Devise Model unable to Work
I'm setting up Devise with this Model: 我正在使用此模型设置Devise:
access.rb access.rb
class Access < ActiveRecord::Base
include UUIDHelper
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
belongs_to :verification
belongs_to :actor, autosave: true
validates_presence_of :username
validates :username, uniqueness: true
validates_length_of :username, maximum: 64
validates_length_of :username, minimum: 3
# Returns the hash digest of the given string. Used for SEEDS FILE
def Access.digest(string)
cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
BCrypt::Engine.cost
BCrypt::Password.create(string, cost: cost)
end
end
20150304041353_create_accesses.rb 20150304041353_create_accesses.rb
class CreateAccesses < ActiveRecord::Migration
def change
create_table :accesses, :id => false do |t|
t.string :id, limit: 36, primary: true, null: false
t.string :actor_id, limit: 36, :required => true
t.string :username, :limit => 64
t.timestamps
end
end
end
and these are the commands from the controller: 这些是来自控制器的命令:
def processAccess(params)
@access.username = params[:access][:username]
@access.password = params[:access][:password]
@access.email = params[:access][:email]
@access.actor = @actor
@access.save!
end
I am trying to get access to register or 'add' in database. 我正在尝试访问数据库中的注册或“添加”。 but as soon as I uncomment 'devise' it just doesn't work. 但是,一旦我取消“设计”的评论,它就不会起作用。 I've also tried manually inputting it over in rails console; 我也尝试过在Rails控制台中手动输入它。 it does work.. What am I missing? 它确实有效。我想念什么?
You need to initialize the Access
model in your controller
's action like : 您需要在controller
的操作中初始化Access
模型,例如:
@access = Access.new
before assigning any values to the @access
instance variable. 在将任何值分配给@access
实例变量之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.