繁体   English   中英

设计模型无法正常工作

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM