authlogic icon indicating copy to clipboard operation
authlogic copied to clipboard

NameError - wrong constant name Object.const_get(camel_cased_word)

Open Codcore opened this issue 3 years ago • 1 comments

I am trying setup Authlogic gem with rails 7. I have simple controller:

class UsersController < ApplicationController
  def new
    render_page 'Registration'
  end

  def create
    @user = User.new(email: '[email protected]', password: 415561)
    if @user.save
      redirect_to root_url
    else
      render_page 'Registration', props: { errors: @user.errors_codes }
    end
  end

  private

  def user_params
    params.require(:user).permit(:name, :surname, :email, :password, :password_confirmation).to_h
  end
end

and simple User model:

class User < ApplicationRecord
  acts_as_authentic do |c|
    c.session_class = Session
    c.crypto_provider = ::Authlogic::CryptoProviders::BCrypt
  end
end

But when I call create action of UsersController, I get error:

NameError - wrong constant name 
      Object.const_get(camel_cased_word)
            ^^^^^^^^^^:
  app/controllers/users_controller.rb:8:in `create'

That error refers to @user.save in UsersController. I can not figure out what is happenning. I tried to debug this line, but did not understand what is going on. Also I tried authlogic gem right from the GitHub repository, but it didn't help.

The most interesing part that all works as intended when I create new instnce of User and then save it from rails console...

Codcore avatar Jun 02 '22 19:06 Codcore

Hi @Codcore, could you paste in the entire error message? The additional stack trace might indicate other places where would look.

Also, are you sure you want to use a capital R in the name of your registrations template - the Rails convention is to use lowercase filenames.

Cheers, Dan

danlaffan avatar Jun 03 '22 09:06 danlaffan