【发布时间】:2019-04-26 12:12:06
【问题描述】:
故事模式
刚开始学习RoR,但短期内需要在项目中添加类似于Loading images from LDAP(不兼容版本)的功能。项目已废弃,我找不到任何相关的信息/文档,所以我在这里寻求帮助。解决方案,教程,任何东西都可以。
错误日志
$ ruby bin/rake redmine:plugins RAILS_ENV="production"
rake aborted!
NoMethodError: undefined method `alias_method_chain' for ApplicationHelper:Module
Did you mean? alias_method
...
需要更新的猴子补丁
插件\redmine_gemavatar\lib\application_helper_gemavatar_patch.rb:
require 'application_helper'
module GemAvatarPlugin
module ApplicationAvatarPatch
def self.included(base)
base.send(:include, InstanceMethods)
base.class_eval do
alias_method_chain :avatar, :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}\" />".html_safe
else
''
end
end
end
end
end
我的尝试/文章
我在这里How To Replace alias_method_chain 找到了好文章,但我不太确定如何将prepend 样式应用于 redmine 插件的猴子补丁。只是无法让它工作:/
【问题讨论】:
-
找到另一篇文章 Module.prepend: a super story 可能对某人有帮助。
标签: ruby ruby-on-rails-5 redmine redmine-plugins alias-method-chain