将 'alias_method_chain :save_attachments, :pasted_images' 替换为 Rails 5.2.3
Replace 'alias_method_chain :save_attachments, :pasted_images' in Rails 5.2.3
我安装了 Redmine 3.4.4 运行,它使用 Ruby 2.2.5-p319 和 Rails 4.2.8。我们想将其升级到最新的 Redmine(当前为 4.0.4),这需要 Rails 5.
我是 运行 使用 4.0.4 使用 Ruby 2.6.3-p62 和 Rails 5.2.3 的新服务器。总的来说没问题,但我们安装了一些我们想要迁移的插件。由于 Rails 5 中的弃用,其中许多都出现了问题。尽管我之前没有在 Rails 上写过 Ruby,但我已经成功地通过了 9 个插件中的 8 个,但我被困在最后一个上,就是想不通。
该插件是我的页面自定义插件,当我尝试迁移数据库和插件时出现此错误:
[centos@redmine]$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ActivitiesController:Class
Did you mean? alias_method
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:11:in `block in included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `class_eval'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `include'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `block (2 levels) in <top (required)>'
因此,很明显已弃用的 'alias_method_chain'
是这里的问题所在。经过一番挖掘后,我在网上找到了很多参考资料,例如 this 一个很好而且清晰的参考资料,但我就是无法编写有效的代码 - 我不断收到语法错误并且无法弄清楚我'我做错了。
这是来自 activities_controller_patch.rb:
的原始片段
module ActivitiesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
helper :issues
helper :queries
alias_method_chain :index, :esi
end
end
即使它不正式支持 Redmine 4,我们也希望尽可能使用这个插件。我希望有更好 Ruby 知识的人能够提供帮助。
而不是
alias_method_chain :index, :esi
你只需使用
alias_method :index_without_esi, :index
alias_method :index, :index_with_esi
It was 某种语法糖。
我安装了 Redmine 3.4.4 运行,它使用 Ruby 2.2.5-p319 和 Rails 4.2.8。我们想将其升级到最新的 Redmine(当前为 4.0.4),这需要 Rails 5.
我是 运行 使用 4.0.4 使用 Ruby 2.6.3-p62 和 Rails 5.2.3 的新服务器。总的来说没问题,但我们安装了一些我们想要迁移的插件。由于 Rails 5 中的弃用,其中许多都出现了问题。尽管我之前没有在 Rails 上写过 Ruby,但我已经成功地通过了 9 个插件中的 8 个,但我被困在最后一个上,就是想不通。
该插件是我的页面自定义插件,当我尝试迁移数据库和插件时出现此错误:
[centos@redmine]$ bundle exec rake db:migrate RAILS_ENV=production
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ActivitiesController:Class
Did you mean? alias_method
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:11:in `block in included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `class_eval'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/lib/my_page_patches/activities_controller_patch.rb:7:in `included'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `include'
/usr/local/src/redmine-4.0.4/plugins/redmine_my_page/init.rb:30:in `block (2 levels) in <top (required)>'
因此,很明显已弃用的 'alias_method_chain'
是这里的问题所在。经过一番挖掘后,我在网上找到了很多参考资料,例如 this 一个很好而且清晰的参考资料,但我就是无法编写有效的代码 - 我不断收到语法错误并且无法弄清楚我'我做错了。
这是来自 activities_controller_patch.rb:
module ActivitiesControllerPatch
def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)
base.class_eval do
unloadable
helper :issues
helper :queries
alias_method_chain :index, :esi
end
end
即使它不正式支持 Redmine 4,我们也希望尽可能使用这个插件。我希望有更好 Ruby 知识的人能够提供帮助。
而不是
alias_method_chain :index, :esi
你只需使用
alias_method :index_without_esi, :index
alias_method :index, :index_with_esi
It was 某种语法糖。