โหมดเนื้อเรื่อง
เพิ่งเริ่มเรียนรู้ RoR แต่ในช่วงเวลาสั้นๆ ฉันต้องเพิ่มฟังก์ชันที่คล้ายกับ กำลังโหลดรูปภาพจาก 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
ความพยายามของฉัน / บทความ
ฉันพบบทความดีๆ ที่นี่ วิธีแทนที่ alias_method_chain แต่ฉันไม่ค่อยแน่ใจว่าจะใช้สไตล์ prepend
กับแพทช์ลิงของปลั๊กอิน redmine ได้อย่างไร แค่ไม่สามารถทำงานได้ :/