lectery 发表于 2013-1-29 07:38:19

rails 2.2.2中ym4r 的bug的修补

今天在rails2.2.2中使用ym4r插件时产生如下错误
"undefined method 'relative_url"
上网查了一下,有两种解决方法:
1.修改“vendor/plugins/ym4r_gm/gm_plugin/map.rb”文件,大约35或36行左右,将
a << "script src=\"#{ActionController::AbrastractRequest.relative_url_root}/javascript/ym4r-gm.js\" type=\"text/javascript\"> </script>\n" unless option[:without_js]中的#{ActionController::AbstractRequest.relative_url_root}
修改为#{ActionController::Base.relative_url_root},修改过后重启服务器即可。
2.I made a file named "PatchYm4rGM.rb" 在 config/initializer 文件夹中新建文件 PatchYm4rGM.rb ,内容如下:
   class GMap      def self.header(options = {})       options[:with_vml] = true unless options.has_key?(:with_vml)      options[:hl] ||= ''      options[:local_search] = false unless options.has_key?(:local_search)      api_key = ApiKey.get(options)      a = "<script src=\"http://maps.google.com/maps?file=api&v=2.x&key=#{api_key}&hl=#{options[:hl]}\" type=\"text/javascript\"></script>\n"      a << "<script src=\"#{ActionController::Base.relative_url_root}/javascripts/ym4r-gm.js\" type=\"text/javascript\"></script>\n" unless options[:without_js]      a << "<style type=\"text/css\">\n v\:* { behavior:url(#default#VML);}\n</style>" if options[:with_vml]      a << "<script src=\"http://www.google.com/uds/api?file=uds.js&v=1.0\" type=\"text/javascript\"></script>" if options[:local_search]   a << "<script src=\"http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js\" type=\"text/javascript\"></script>\n" if options[:local_search]       a << "<style type=\"text/css\">@import url(\"http://www.google.com/uds/css/gsearch.css\");@import url(\"http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css\");}</style>" if options[:local_search]      a    end   end
这种方法不需要修改插件代码,所以避免了插件更新引发的问题。

详见:http://railsforum.com/viewtopic.php?id=24839
页: [1]
查看完整版本: rails 2.2.2中ym4r 的bug的修补