简体   繁体   English

升级到Rails 5.1,gem`query_reviewer`和不赞成使用的方法`alias_method_chain`

[英]Upgrade to Rails 5.1, gem `query_reviewer` and deprecated method `alias_method_chain`

Rails community! Rails社区!

I'm having an issue about upgrading on Rails project from Rails 4.2 to Rails 5.2, issue related to the step from Rails 5.0 to 5.1 我在将Rails项目从Rails 4.2升级到Rails 5.2时遇到问题,与从Rails 5.0升级到5.1的问题有关

/gems/query_reviewer-0.2.2/lib/query_reviewer/mysql_adapter_extensions.rb:4:in `included': undefined method `alias_method_chain' for ActiveRecord::ConnectionAdapters::Mysql2Adapter:Class (NoMethodError)

I've read a lot of related questions here, and I understood that method alias_method_chains is deprecated with Rails 5.1... 我在这里阅读了很多相关的问题,并且我知道方法Rails 5.1不推荐使用alias_method_chains方法...

However, here, issue comes from a gem, especially gem query_reviewer ( github , rubygems ): Last version of this gem is 0.2.2 (septembre 16, 2013) and includes the deprecated method: 但是,这里的问题来自一个gem,尤其是gem query_reviewergithubrubygems ):这个gem的最新版本是0.2.2(2013年9月16日),其中包含不推荐使用的方法:

module QueryReviewer
  module MysqlAdapterExtensions
    def self.included(base)
      base.alias_method_chain :select, :review
      base.alias_method_chain :update, :review
      base.alias_method_chain :insert, :review
      base.alias_method_chain :delete, :review
    end

Obviously, this gem is not available with Rails 5.1, and obvious but painful option would be to look for an other gem... But, maybe, someone had the same issue and found a better way to answer to this 1st question as StackOverflow user ;) ? 显然,该gem在Rails 5.1中不可用,明显但痛苦的选择是寻找其他gem ...但是,也许有人遇到了同样的问题,并且找到了一个更好的方法来作为StackOverflow用户来回答第一个问题;)

Thanks by advance 预先感谢

In rails 5+ alias_method_chain has removed, so in place of this we can use alias_method like below 在Rails 5+中,alias_method_chain已删除,因此可以代替alias_method来使用,如下所示

  base.alias_method :select_without_review, :select
  base.alias_method :select, :select_with_review
  base.alias_method :update_without_review, :update
  base.alias_method :update, :update_with_review
  base.alias_method :insert_without_review, :insert
  base.alias_method :insert, :insert_with_review
  base.alias_method :delete_without_review, :delete
  base.alias_method :delete, :delete_with_review 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM