[英]Devise Model unable to Work
我正在使用此模型設置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控制台中手動輸入它。 它確實有效。我想念什么?
您需要在controller
的操作中初始化Access
模型,例如:
@access = Access.new
在將任何值分配給@access
實例變量之前。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.