Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

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

Open
nynhex opened this issue Jul 9, 2017 · 12 comments

Comments

@nynhex
Copy link

nynhex commented Jul 9, 2017

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
Copy link

maynardewm commented Jul 10, 2017

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
Copy link
Author

nynhex commented Jul 10, 2017

@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
Copy link

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

@MohamedBrary
Copy link

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:

  • To unpack the gem into lib/gems/
    gem unpack devise_security_extension --target=lib/gems/

  • Edit with your an editor that has 'Replace All' functionality the following in gem folder:
    'before_filter' to 'before_action'
    'ActionDispatch::Callbacks.to_prepare' to 'ActiveSupport::Reloader.to_prepare'

  • Update your Gemfile.rb to point to the unpacked gem (make sure the name of the folder is correct):
    gem 'devise_security_extension', :path => "lib/gems/devise_security_extension-0.9.2"

It should work fine then!

@narutoo9x
Copy link

narutoo9x commented Jul 26, 2017

@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
Copy link

Uysim commented Aug 24, 2017

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

@RalphShnelvar
Copy link

@MohamedBrary, whomever you are, bless you!

@tranhuyhoangbka
Copy link

tranhuyhoangbka commented Nov 17, 2020

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
Copy link

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

@ntli239
Copy link

ntli239 commented Nov 25, 2020

The most recent fix: bec97d5#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
Copy link

@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
Copy link

devtoro commented Jan 12, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants