简体   繁体   中英

Devise Model unable to Work

I'm setting up Devise with this Model:

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

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; it does work.. What am I missing?

You need to initialize the Access model in your controller 's action like :

@access = Access.new

before assigning any values to the @access instance variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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