gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 07:44:05 27 4
gpt4 key购买 nike

在我使用 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com