我正在使用此模型设置Devise:
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
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
这些是来自控制器的命令:
def processAccess(params)
@access.username = params[:access][:username]
@access.password = params[:access][:password]
@access.email = params[:access][:email]
@access.actor = @actor
@access.save!
end
我正在尝试访问数据库中的注册或“添加”。但是一旦我取消注释'设计'它就行不通。我也试过在rails console中手动输入它;它确实有效..我错过了什么?
答案 0 :(得分:0)
您需要在Access
的操作中初始化controller
模型,如:
@access = Access.new
在将任何值分配给@access
实例变量之前。