Ruby 如何将redmine插件升级到rails 5,alias_method_chain现在不推荐使用 故事模式

Ruby 如何将redmine插件升级到rails 5,alias_method_chain现在不推荐使用 故事模式,ruby,ruby-on-rails-5,redmine,redmine-plugins,alias-method-chain,Ruby,Ruby On Rails 5,Redmine,Redmine Plugins,Alias Method Chain,刚开始学习RoR,但在短时间内我需要在我们的项目中添加类似于(不兼容版本)的功能。项目被取消了,我找不到任何相关的信息/文档,所以我在这里寻求帮助。解决方案,教程,任何东西都可以 错误日志 $ruby-bin/rake-redmine:plugins-RAILS\u ENV=“production” 雷克流产了! NoMethodError:ApplicationHelper:Module的未定义方法“别名\u方法\u链” 你是说?别名法 ... 猴子补丁需要更新 plugins\redmin

刚开始学习RoR,但在短时间内我需要在我们的项目中添加类似于(不兼容版本)的功能。项目被取消了,我找不到任何相关的信息/文档,所以我在这里寻求帮助。解决方案,教程,任何东西都可以

错误日志
$ruby-bin/rake-redmine:plugins-RAILS\u ENV=“production”
雷克流产了!
NoMethodError:ApplicationHelper:Module的未定义方法“别名\u方法\u链”
你是说?别名法
...
猴子补丁需要更新 plugins\redmine\u gemavatar\lib\application\u helper\u gemavatar\u patch.rb:

require'application\u helper'
模块GemAvatarPlugin
模块ApplicationAvatarPatch
def自带(基本)
base.send(:include,InstanceMethods)
基本类\u评估do
别名\u方法\u链:头像,:头像
结束
结束
模块实例方法
def avatar_with_gemavatar(用户,选项={})
如果设置.gravatar_已启用?&&用户。您是?(用户)
选项。合并!({:ssl=>(已定义的?(请求)和&request.ssl?,:default=>Setting.gravatar_default})
选项[:大小]=“64”,除非选项[:大小]
头像url=url\u用于:控制器=>:图片,:操作=>:删除,:用户id=>用户
安全返回“.html”
其他的
''
结束
结束
结束
结束
结束
我的尝试/文章
我在这里找到了一篇好文章,但我不太确定如何将
prepend
风格应用到redmine插件的monkey补丁中。只是无法让它工作:/

您可以使用
alias\u方法
而不是
alias\u方法链
,但我正在搜索类似
prepend
的解决方案

alias\u方法:无化身的化身,:化身
别名\u方法:头像,:头像\u与头像
UPD: 但它发出警告:

/app/helpers/application\u helper.rb:180:警告:已初始化常量ApplicationHelper
::记录链接
/app/helpers/application\u helper.rb:180:警告:记录链接的先前定义在此
/app/helpers/application\u helper.rb:199:警告:已初始化常量ApplicationHelper
::附件\u容器\u链接
/app/helpers/application\u helper.rb:199:警告:附件容器的先前定义
NK在这里
/app/helpers/application\u helper.rb:1053:警告:已初始化常量ApplicationHelpe
r::链接
/app/helpers/application\u helper.rb:1053:警告:链接的先前定义在此
退出
UPD: 作为
require'application\u helper'
可以删除以防止出现警告,因为它已经包含在核心中。

这与否有关

如果是这样,我会这样做:

  • init.rb
    文件中,更改以下内容:
RedmineApp::Application.config.after\u初始化do
发送(:include,GemAvatarPlugin::ApplicationAvatarPatch)
结束
为此:

RedmineApp::Application.config.after\u初始化do
ApplicationHelper.prepend(GemAvatarPlugin::ApplicationAvatarPatch)
结束
  • lib/application\u helper\u gemavatar\u patch.rb
    中,更改以下内容:
require'application\u helper'
模块GemAvatarPlugin
模块ApplicationAvatarPatch
def自带(基本)
base.send(:include,InstanceMethods)
基本类\u评估do
别名\u方法\u链:头像,:头像
结束
结束
模块实例方法
def avatar_with_gemavatar(用户,选项={})
#为清晰起见,省略了方法内容
结束
结束
结束
结束
为此:

RedmineApp::Application.config.after_initialize do    
  ApplicationHelper.include ApplicationAvatarPatch
end
模块GemAvatarPlugin
模块ApplicationAvatarPatch
def化身(用户,选项={})
#为清晰起见,省略了方法内容
结束
结束
结束

我会删除
require'application\u helper'
,因为我不明白为什么需要它

我还尝试更新这个插件。我举了一个例子

在init.rb中更改了以下内容:

RedmineApp::Application.config.after_initialize do
  ApplicationHelper.send(:include, GemAvatarPlugin::ApplicationAvatarPatch)
end
为此:

RedmineApp::Application.config.after_initialize do    
  ApplicationHelper.include ApplicationAvatarPatch
end
修补的lib/application\u helper\u gemavatar\u patch.rb如下所示:

module ApplicationAvatarPatch    
def self.included(base)
    base.send(:include, InstanceMethods)

    base.class_eval do
        alias_method :avatar_without_gemavatar, :avatar
        alias_method :avatar, :avatar_with_gemavatar
    end
end

module InstanceMethods
    def avatar_with_gemavatar(user, options = { })
        if Setting.gravatar_enabled? && user.is_a?(User)
            options.merge!({:ssl => (defined?(request) && request.ssl?), :default => Setting.gravatar_default})
            options[:size] = "64" unless options[:size]
            avatar_url = url_for :controller => :pictures, :action => :delete, :user_id => user
            return "<img class=\"gravatar\" width=\"#{options[:size]}\" height=\"#{options[:size]}\" src=\"#{avatar_url}\" alt=\"Gemavatar text\" />".html_safe
        else
            avatar_without_gemavatar(user, options)
        end
    end
end
end
在redmine_local_avatars插件中,redmine 4.1有一个不同的补丁


更新:我设置了一个github存储库,其中包含以下更改:

找到了另一篇可能对某人有帮助的文章。您不能
要求“应用程序\u助手”
。它在运行时是必需的,您可以在
/app
rails应用文件夹中找到它。您可能试图要求错误的文件。您可以通过在终端中运行
echo$LOAD\u path
来显示自动加载路径,并获取有关自动加载路径的更多信息。请在
github
上共享项目的
存储库
,以及
插件\redmine\u gemavatar\lib\application\u helper\u gemavatar\u patch.rb的url
,这样我就可以发布这个问题的解决方案。由于某些原因,它不起作用。仅加载gravatar_默认图像。似乎它从未进入图片模型,并要求图片为
/people/avatar?id=1005
,而它应该是smth,如
/gemavatar/1005
嗯,这很奇怪,它对我来说工作正常。。。您是否安装了另一个插件,如
redmine\u people
?另外,如果您从
redmine
目录启动
rails c
,并运行
ApplicationHelper,您会得到什么?包括的\u模块
?是的,我正在使用people。此处包含的模块:
[GemAvatarPlugin::ApplicationAvatarPatch,RedminePeople::Patches::ApplicationHelperPatch::InstanceMethods,RedminePeople::Patches::ApplicationHelperPatch,Redmine::Helpers::URL,Redmine::Hook::Helper,Redmine::主题::Helper,Redmine::SudoMode::Helper,Redmine::Pagination n::Helper,GravatalPerper::PublicMethods,Redmine::I18n,Redmine::WikiFormating::宏::定义