tomichj / invitation

A Rails gem that can send 'scoped' invitations
MIT License
77 stars 28 forks source link

I think 0.4.2 may have broke my app #10

Closed vincentwoo closed 7 years ago

vincentwoo commented 7 years ago
[4] ! Unable to load application: NoMethodError: undefined method `constantize' for User (call 'User.connection' to establish a connection):Class
Did you mean?  constants
bundler: failed to load command: puma (/app/vendor/bundle/ruby/2.4.0/bin/puma)
NoMethodError: undefined method `constantize' for User (call 'User.connection' to establish a connection):Class
Did you mean?  constants
  /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing'
  /app/vendor/bundle/ruby/2.4.0/gems/invitation-0.4.2/lib/invitation/configuration.rb:65:in `user_model'
  /app/vendor/bundle/ruby/2.4.0/gems/invitation-0.4.2/lib/invitation/configuration.rb:69:in `user_model_class_name'
  /app/vendor/bundle/ruby/2.4.0/gems/invitation-0.4.2/app/models/invite.rb:7:in `<class:Invite>'
  /app/vendor/bundle/ruby/2.4.0/gems/invitation-0.4.2/app/models/invite.rb:5:in `<top (required)>'
  /app/vendor/bundle/ruby/2.4.0/gems/skylight-1.3.1/lib/skylight/probes.rb:81:in `require'
  /app/vendor/bundle/ruby/2.4.0/gems/skylight-1.3.1/lib/skylight/probes.rb:81:in `require'
  /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.2/lib/active_support/dependencies.rb:292:in `block in require'
...
vincentwoo commented 7 years ago

Our config file looks like:

Invitation.configure do |config|
  config.routes = false
  config.user_model = ::User
  config.user_registration_url =
    ->(params) { Rails.application.routes.url_helpers.new_user_registration_url(params) }
end

Did the string constantization thing break something?

vincentwoo commented 7 years ago

Confirmed that using '::User' or just leaving the config line out (since Invitation sets one by default) fixes the issue. I think the gem should accept either format and that you should put out a fix and yank 0.4.2.

tomichj commented 7 years ago

You're right, the gem configuration's user_model setting should accept both the Class or a String. My apologies for this oversight.

Setting the user model class directly (rather than just it's name) can cause other errors in some cases, hence the change (see https://github.com/tomichj/invitation/issues/8).

I'm going to add a warning when user_model is set directly to the user class, but will allow it to accept either a String (the name) or the Class.

Fix coming shortly.

tomichj commented 7 years ago

0.4.3 released with fix

tomichj commented 7 years ago

thanks for the bug report, I appreciate it