Raj*_*tan 3 ruby ruby-on-rails ruby-on-rails-3 strong-parameters ruby-on-rails-4
在使用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
Run Code Online (Sandbox Code Playgroud)
由于强烈建议在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
Run Code Online (Sandbox Code Playgroud)
User.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
Run Code Online (Sandbox Code Playgroud)
现在,当我尝试使用下面给出的表格进行注册时,

我收到以下附加错误.请帮我解决一下.

And*_*tad 10
从authlogic github帐户的这个问题
Authlogic已将其默认加密系统从SHA512更改为SCrypt.
看来你需要在你的gemfile中使用它
gem 'authlogic', '~> 3.4.0'
gem 'scrypt'
Run Code Online (Sandbox Code Playgroud)
如果您不想要SCrypt,可以使用Sha512
acts_as_authentic do |c|
c.crypto_provider = Authlogic::CryptoProviders::Sha512
end
Run Code Online (Sandbox Code Playgroud)
在您的User.rb中
您还可能需要指定authlogic gem的版本
gem 'authlogic', github: 'binarylogic/authlogic', ref: 'e4b2990d6282f3f7b50249b4f639631aef68b939'
Run Code Online (Sandbox Code Playgroud)
但我想这很快就会解决
| 归档时间: |
|
| 查看次数: |
1678 次 |
| 最近记录: |