【问题标题】:alias_method_chain fix for Devise with Rails 5 API?使用 Rails 5 API 进行设计的 alias_method_chain 修复?
【发布时间】:2015-10-12 02:49:21
【问题描述】:

Devise 一直给我这个消息DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from <class:RouteSet> at /.../.rvm/gems/ruby-2.2.3/gems/devise-3.3.0/lib/devise/rails/routes.rb:27) 这就是 Devise 的 routes.rb 的样子

module ActionDispatch::Routing
  class RouteSet #:nodoc:
    # Ensure Devise modules are included only after loading routes, because we
    # need devise_for mappings already declared to create filters and helpers.
    def finalize_with_devise!
      result = finalize_without_devise!

      @devise_finalized ||= begin
        if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)
          warn "[DEVISE] We have detected that you are using devise_for inside engine routes. " \
            "In this case, you probably want to set Devise.router_name = MOUNT_POINT, where "   \
            "MOUNT_POINT is a symbol representing where this engine will be mounted at. For "   \
            "now Devise will default the mount point to :main_app. You can explicitly set it"   \
            " to :main_app as well in case you want to keep the current behavior."
        end

        Devise.configure_warden!
        Devise.regenerate_helpers!
        true
      end

      result
    end
    alias_method_chain :finalize!, :devise
  end

这里可以快速修复吗?

【问题讨论】:

    标签: devise ruby-on-rails-5


    【解决方案1】:

    候选设计版本支持 Rails 5,将其放入 ol' Gemfile

    gem "devise", '~> 4.0.0.rc1'

    【讨论】:

      【解决方案2】:

      请检查以下内容:

      1) Rails 5 的 routes.rb 文件的更新代码中有这个要点

      https://raw.githubusercontent.com/chbonser/devise/f05dd9dddb33cbc1739266637eafa2299661f517/lib/devise/rails/routes.rb

      2) 使用终端获取 gem 文件夹路径:

      gem environment
      

      你应该得到路径,这将帮助你找到设计 gem 文件夹。

      浏览以设计 gem(类似这样的东西):

      cd /usr/local/rvm/gems/ruby-2.2.2/gems/devise-3.5.2/lib/devise
      

      并编辑/更新文件,如 failure_app.rb:

      nano failure_app.rb
      

      评论/删除 RackDelegation 参考:

      https://github.com/plataformatec/devise/issues/3736

      等等

      【讨论】:

      • 我之前看到过同样的线程并尝试删除 RackDelegation 引用,它导致的只是一条消息 dynamic_matchers.rb:21:in method_missing': undefined method devise' for User (call 'User.connection' to establish a connection):Class (NoMethodError)
      猜你喜欢
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-12-16
      • 1970-01-01
      • 1970-01-01
      • 2017-10-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多