簡體   English   中英

NoMethodError:未定義的方法`encrypted_pa​​ssword設計寶石

[英]NoMethodError: undefined method `encrypted_password devise gem

this is my user model:


class User < Account
       devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable


          attr_accessible :email, :password, :password_confirmation, :remember_me

       devise :database_authenticatable,
       :ga_otp_authenticatable,
    :yk_otp_authenticatable,
    :registerable,
    :confirmable,
    :recoverable,
    :trackable,
    :validatable,
    :lockable,
    :timeoutable

  # Setup accessible (or protected) attributes for your model
  attr_accessible :password, :password_confirmation, :remember_me, :time_zone, :require_ga_otp, :require_yk_otp, :full_name, :address

  attr_accessor :captcha,
    :skip_captcha,
    :new_password,
    :new_password_confirmation,
    :current_password

  before_validation :generate_name,
    :on => :create

  has_many :trade_orders,
    :dependent => :destroy

  has_many :purchase_trades,
    :class_name => "Trade",
    :foreign_key => "buyer_id"

  has_many :sale_trades,
    :class_name => "Trade",
    :foreign_key => "seller_id"

  has_many :invoices,
    :dependent => :destroy

  has_many :yubikeys,
    :dependent => :destroy

  has_many :bank_accounts,
    :dependent => :destroy

  has_many :tickets,
    :dependent => :destroy

  #has_many :tickets,
  #  :dependent => :destroy

  validates :email,
    :uniqueness => true,
    :presence => true

  validate :captcha do
    if captcha.nil? and new_record?
      unless skip_captcha
        errors[:captcha] << I18n.t("errors.answer_incorrect")
      end
    end
  end

  def captcha_checked!
    self.captcha = true
  end

  def bitcoin_address
    super or (generate_new_address && super)
  end

  def qr_code
    if @qrcode.nil?
      @qrcode = RQRCode::QRCode.new(bitcoin_address, :size => 6)
    end
    @qrcode
  end

  def confirm!
    super
    UserMailer.registration_confirmation(self).deliver
  end

  protected

  def self.find_for_database_authentication(warden_conditions)
    conditions = warden_conditions.dup
    name = conditions.delete(:name)
    where(conditions).where(["name = :value OR email = :value", { :value => name }]).first
  end

  def generate_name
    self.name = "BF-U#{"%06d" % (rand * 10 ** 6).to_i}"
  end
end

這是我的帳戶模型:

     class Account < ActiveRecord::Base
  has_many :account_operations

  has_many :used_currencies,
    :dependent => :destroy

  belongs_to :parent,
    :class_name => 'Account'

  validates :name,
    :presence => true,
    :uniqueness => true

  # BigDecimal returned here
  def balance(currency, options = {} )
    account_operations.with_currency(currency).with_confirmations(options[:unconfirmed]).with_processed_active_deposits_only.map(&:amount).sum.round(5).abs
  end

  # Generates a new receiving address if it hasn't already been refreshed during the last hour
  def generate_new_address
    unless last_address_refresh && last_address_refresh > DateTime.now.advance(:hours => -1)
      self.last_address_refresh = DateTime.now
      self.bitcoin_address = Bitcoin::Client.instance.get_new_address(id.to_s)
      save
    end
  end

  def max_withdraw_for(currency)
    Transfer.round_amount(self.balance(currency), currency)
  end

  def self.storage_account_for(currency)
    account_name = "storage_for_#{currency.to_s.downcase}"
    account = find_by_name(account_name)

    if account
      account
    else
      Account.create! do |a|
        a.name = account_name
      end
    end
  end
end

我的問題是我嘗試輸入密碼,但不接受密碼字段。 密碼不能為空給出錯誤。

我嘗試手動創建用戶。 在這里,它給錯誤未定義的方法加密的密碼。

如何解決這個問題呢?

嘗試一下.....您的模型上是否有加密密碼列?

attr_accessible :email, :password, :password_confirmation, :remember_me, :encrypted_password

僅僅因為它的attr_accessable並不意味着該屬性存在,而是意味着您可以訪問它(如果它確實存在)。 進入rails控制台並運行:

User.new.respond_to?(:encrypted_password=)

如果返回true,則您的模型中有該列,否則,您需要確保運行正確的遷移。

User.new.respond_to?(:encrypted_password=) => false

I run rake db:migrate:reset and it work!!!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM