ruby-on-rails - UsersController 中的 NameError -(未初始化的常量 SCrypt)

标签 ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 strong-parameters

在我使用 Rails 4.1.0Ruby 2.1.0 的 Rails 应用中,

我一直在使用 Authlogic 对用户进行身份验证。

users_controller.rb 中,我有一个创建方法,如下所示。

def create
  @user = User.new(user_params) #this line has the error
  respond_to do |format|
    if @user.save
      format.html { redirect_to_target_or_default account_url, notice: 'User was successfully created.' }
    else
      format.html { render action: 'new' }
    end
  end
end

由于在 Rails 4.0 中强烈推荐使用强参数,attr_accessible 已从 User 模型中删除,下面给定的代码已添加到 users_controller.rb

private

    # Never trust parameters from the scary internet, only allow the white list through.
    def user_params
      params.require(:user).permit(:login, :email, :password, :password_confirmation, :role_ids)
    end

用户.rb

class User < ActiveRecord::Base

  #attr_accessible :login, :email, :password, :password_confirmation, :role_ids

  has_many :articles
  has_many :comments
  has_many :assignments

  has_many :roles, :through => :assignments

  def role_symbols
    roles.map do |role|
      role.name.underscore.to_sym
    end
  end


  acts_as_authentic do |c|
    c.login_field = :login
  end


  def deliver_password_reset_instructions!
    reset_perishable_token!
    Notifier.deliver_password_reset_instructions(self)
  end

end

现在,当我尝试使用下面给出的表格进行注册时,

enter image description here

我收到以下附加错误。请帮助我找到解决方案。

enter image description here

最佳答案

从这里issue在 authlogic github 帐户上

Authlogic 已将其默认加密系统从 SHA512 更改为 SCrypt。

看来你的 gemfile 中需要这个

gem 'authlogic', '~> 3.4.0'
gem 'scrypt'

如果你不想使用 SCrypt,你可以使用 Sha512 来放置它

acts_as_authentic do |c|
  c.crypto_provider = Authlogic::CryptoProviders::Sha512
end

在你的 User.rb 中

您可能还需要指定 authlogic gem 的版本

gem 'authlogic', github: 'binarylogic/authlogic', ref: 'e4b2990d6282f3f7b50249b4f639631aef68b939'

但我想这很快就会被修复

关于ruby-on-rails - UsersController 中的 NameError -(未初始化的常量 SCrypt),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22170226/

相关文章:

ruby-on-rails - 如何在 Rails3 中使用子域作为参数?

ruby-on-rails - Rails 迁移 - 根据条件修改行

ruby-on-rails - rails +Capistrano : Sidekiq doesn't always start when new code is deployed

ruby-on-rails - 获取复选框的值 [Ruby/Sinatra(Rails)]

ruby-on-rails - 如何建模用户自定义表模型与字段模型的关系

ruby-on-rails - 为 memcached 和 Rails 组合片段和对象缓存的最佳方法

ruby - 在命令行上将参数传递给 Rspec 测试

ruby-on-rails-3 - Stripe订阅后可以更新订阅金额吗?

ruby - Ruby 基准测试如何计算线程内的总 CPU 时间

ruby - Mandrill-api Excon::错误::SocketError