rails.rb 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require 'devise/rails/routes'
  2. require 'devise/rails/warden_compat'
  3. module Devise
  4. class Engine < ::Rails::Engine
  5. config.devise = Devise
  6. # Initialize Warden and copy its configurations.
  7. config.app_middleware.use Warden::Manager do |config|
  8. Devise.warden_config = config
  9. end
  10. # Force routes to be loaded if we are doing any eager load.
  11. config.before_eager_load { |app| app.reload_routes! }
  12. initializer "devise.url_helpers" do
  13. Devise.include_helpers(Devise::Controllers)
  14. end
  15. initializer "devise.omniauth" do |app|
  16. Devise.omniauth_configs.each do |provider, config|
  17. app.middleware.use config.strategy_class, *config.args do |strategy|
  18. config.strategy = strategy
  19. end
  20. end
  21. if Devise.omniauth_configs.any?
  22. Devise.include_helpers(Devise::OmniAuth)
  23. end
  24. end
  25. initializer "devise.mongoid_version_warning" do
  26. if defined?(Mongoid)
  27. require 'mongoid/version'
  28. if Mongoid::VERSION.to_f < 2.1
  29. puts "\n[DEVISE] Please note that Mongoid versions prior to 2.1 handle dirty model " \
  30. "object attributes in such a way that the Devise `validatable` module will not apply " \
  31. "its usual uniqueness and format validations for the email field. It is recommended " \
  32. "that you upgrade to Mongoid 2.1+ for this and other fixes, but if for some reason you " \
  33. "are unable to do so, you should add these validations manually.\n"
  34. end
  35. end
  36. end
  37. initializer "devise.fix_routes_proxy_missing_respond_to_bug" do
  38. # We can get rid of this once we support only Rails > 3.2
  39. ActionDispatch::Routing::RoutesProxy.class_eval do
  40. def respond_to?(method, include_private = false)
  41. super || routes.url_helpers.respond_to?(method)
  42. end
  43. end
  44. end
  45. end
  46. end