【发布时间】:2014-03-04 11:06:13
【问题描述】:
在我使用 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
现在,当我尝试使用下面给出的表格进行注册时,
我收到以下附加错误。请帮我解决。
【问题讨论】:
-
SCrypt是一个 Ruby gem,我想你用它来做密码散列?您可能没有安装 gem,或者它没有添加到您的 Gemfile 中。 rubygems.org/gems/scrypt -
你能发布你的用户模型吗? authlogic 使用 SCrypt 来解密密码。这被调用了,但没有找到。我会检查你的 authlogic 实现是否正确。你确定 authlogic gem 支持 rails 4.1 和 ruby 2.1.1
-
@Andreas Lyngstad:问题已更新。我希望 Authlogic 支持 Rails 4.0
-
@Rajesh CO 也许您应该接受我的回答以供将来参考?
-
@AndreasLyngstad:接受
标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4 strong-parameters