小编and*_*wle的帖子

为什么update_attributes会破坏我的Rails应用程序?

原始问题

我在Ruby 1.9.2上运行Rails 3.0.1.以下是相关的模型,控制器和视图.

user.rb:

class User < ActiveRecord::Base
  belongs_to :directory

  attr_accessor :new_password, :new_password_confirmation

  validates_confirmation_of :new_password, :if => :password_changed?

  before_save :hash_password, :if => :password_changed?

  def self.authenticate(login, password)

    # Check to see if the user exists
    if user = find_by_login(login)

      # If this is an directory user, authenticate them against their directory
      if user.directory
        return directory_auth user, password

      # Otherwise, authenticate them against the local database
      elsif user.hash == Digest::SHA2.hexdigest(user.salt + password)
        return user
      end
    end
    return nil
  end

  def …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

4
推荐指数
1
解决办法
1519
查看次数

标签 统计

ruby-on-rails ×1