phatworx / devise_security_extension

An enterprise security extension for devise, trying to meet industrial standard security demands for web applications.
MIT License
747 stars 346 forks source link

Gem Load Error is: undefined method `to_prepare' for ActionDispatch::Callbacks:Class #223

Open nynhex opened 7 years ago

nynhex commented 7 years ago

The devise_security_extension bundles fine, but the install command fails with the following stack trace.

Rails: 5.1 Ruby: 2.4.1

rails generate devise_security_extension:install


/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:85:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'devise_security_extension'.
Gem Load Error is: undefined method `to_prepare' for ActionDispatch::Callbacks:Class
Did you mean?  to_param
Backtrace for gem load error is:
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/devise_security_extension-0.9.2/lib/devise_security_extension/rails.rb:7:in `<class:Engine>'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/devise_security_extension-0.9.2/lib/devise_security_extension/rails.rb:2:in `<module:DeviseSecurityExtension>'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/devise_security_extension-0.9.2/lib/devise_security_extension/rails.rb:1:in `<top (required)>'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in `require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in `block in require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:258:in `load_dependency'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/activesupport-5.1.1/lib/active_support/dependencies.rb:292:in `require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/devise_security_extension-0.9.2/lib/devise_security_extension.rb:92:in `<top (required)>'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:82:in `require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:82:in `block (2 levels) in require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:77:in `each'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:77:in `block in require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:66:in `each'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:66:in `require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler.rb:108:in `require'
/Users/nynhex/Dropbox/logiccad/config/application.rb:7:in `<top (required)>'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
-e:1:in `<main>'
Bundler Error Backtrace:
 (Bundler::GemRequireError)
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:77:in `each'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:77:in `block in require'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:66:in `each'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler/runtime.rb:66:in `require'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/bundler-1.15.1/lib/bundler.rb:108:in `require'
    from /Users/nynhex/Dropbox/logiccad/config/application.rb:7:in `<top (required)>'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `require'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:92:in `preload'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:153:in `serve'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/nynhex/.rbenv/versions/2.4.1/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from -e:1:in `<main>'````
maynardewm commented 7 years ago

to_prepare is deprecated in Rails 5.1. I'm sorry I don't have a solution, but this is why you are getting this error. This gem hasn't been updated in a bit.

nynhex commented 7 years ago

@maynardewm No problem, I was able to write my own method to limit concurrent sessions in devise. Is there any room for maintainers? I'd love to help bring this gem up to date with rails 5.1

MohamedBrary commented 7 years ago

@nynhex How did you solve this issue? Can you post here your solution please? Thanks!

MohamedBrary commented 7 years ago

In case anyone has the same issue, this is what I did, till it gets upgraded to Rails 5.1.

In the console, at your application root:

It should work fine then!

narutoo9x commented 7 years ago

@MohamedBrary @nynhex I read the newest code, the deprecated was fixed. So, I just add the link to GitHub repo. Like below

gem 'devise_security_extension', git: 'https://github.com/phatworx/devise_security_extension.git'

Is It Okay? It works fine for me.

@MohamedBrary I don't think your solution will resolve the problem on production.

Uysim commented 7 years ago

I think the code is running well in master branch. Why don't we release it to ruby gem?

RalphShnelvar commented 6 years ago

@MohamedBrary, whomever you are, bless you!

tranhuyhoangbka commented 4 years ago

The error appear when i use this gem with Rails 6.0.3.1. Please fix it.

Bundler could not find compatible versions for gem "railties": In snapshot (Gemfile.lock): railties (= 6.0.3.1)

In Gemfile: devise_security_extension was resolved to 0.10.0, which depends on railties (>= 3.2.6, < 6.0)

rails (~> 6.0.3.1) was resolved to 6.0.3.1, which depends on
  railties (= 6.0.3.1)
tranhuyhoangbka commented 4 years ago

Everyone above issue is fixed already. It can run with Rails 6.0.3 now. Thanks!

ntli239 commented 4 years ago

The most recent fix: https://github.com/phatworx/devise_security_extension/commit/bec97d5cbeee3a4554db2de8319daa2e51bf53ca#diff-ccd0262315867a38631692fd09ec4768a909c4e5a47fe81a58a21a5f1eb0922f

broke it for early rails versions (we are on 5.2.4.3)


Bundler could not find compatible versions for gem "railties":
  In Gemfile:
    devise_security_extension (~> 0.10.0) was resolved to 0.10.0, which depends on
      railties (~> 6.0.3, >= 3.2.6)

    rails (= 5.2.4.3) was resolved to 5.2.4.3, which depends on
      railties (= 5.2.4.3)

@hoangth, Wouldn't just

  s.add_runtime_dependency 'railties', '>= 3.2.6'

be enough for this use case?

tranhuyhoangbka commented 4 years ago

@ntli239 Oh my god. That is my mistake. I'm so sorry. Then I have already made a new pull request to fix that error. https://github.com/phatworx/devise_security_extension/pull/250/files Now only wait for merging.

devtoro commented 3 years ago

Any updates on that?

For the time being I have forked the repo and I am using my forked version. Seems to be working fine.