Search code examples
ruby-on-railsrubyruby-on-rails-3ruby-on-rails-4strong-parameters

NameError in UsersController - (uninitialized constant SCrypt)


In my Rails app using Rails 4.1.0 and Ruby 2.1.0,

I have been authenticating users using Authlogic.

In users_controller.rb, I have a create method as given below.

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

Since strong parameters are strongly recommended in Rails 4.0, attr_accessible is removed from User model and below given code added to 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

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

Now, when I try to register using the form given below,

enter image description here

I'm getting the below attached error. Please help me to have a solution.

enter image description here


Solution

  • From this issue on the authlogic github account

    Authlogic has changed its default encryption system from SHA512 to SCrypt.

    It seems that you need this in your gemfile

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

    If you don't want SCrypt you can use Sha512 by putting this

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

    in your User.rb

    You also might need to specify the version of the authlogic gem

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

    but I guess this will be fixed soon