在我使用 Rails 4.1.0 和 Ruby 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
现在,当我尝试使用下面给出的表格进行注册时,
我收到以下附加错误。请帮助我找到解决方案。
最佳答案
从这里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/