Jig*_*hel 5 ruby-on-rails-2 ruby-2.1
我有一个遗留的Rails应用程序,我想升级到最近的Rails和Ruby版本.首先,我试图用Ruby 2.1.2设置应用程序
$ rails -v
Rails 2.3.18
$ ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [i686-linux]
Run Code Online (Sandbox Code Playgroud)
当我尝试运行rake任务时rake db:schema:load RAILS_ENV=test遇到错误
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
Run Code Online (Sandbox Code Playgroud)
通过Google搜索我发现以下参考https://github.com/rails/rails/issues/10514,其中提到Rails 2.3和Ruby 2+版本之间存在不兼容性.
任何人都可以帮我申请参考链接中提到的猴子补丁吗?
谢谢,Jignesh
Jig*_*hel 10
最后解决了错误
can not load translations from /activesupport-2.3.18/lib/active_support/locale/en.yml, the file type yml is not known
Run Code Online (Sandbox Code Playgroud)
通过猴子修补Rails的I18n :: Backend :: Base#load_file(filename)方法.
解决方案如下:
1.1创建一个名为ruby2.rb/ config/initializers 的文件
1.2添加以下内容 /config/initializers/ruby2.rb
if Rails::VERSION::MAJOR == 2 && RUBY_VERSION >= '2.0.0'
module I18n
module Backend
module Base
def load_file(filename)
type = File.extname(filename).tr('.', '').downcase
# As a fix added second argument as true to respond_to? method
raise UnknownFileType.new(type, filename) unless respond_to?(:"load_#{type}", true)
data = send(:"load_#{type}", filename) # TODO raise a meaningful exception if this does not yield a Hash
data.each { |locale, d| store_translations(locale, d) }
end
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
1.3终于跑了
$ rake db:schema:load RAILS_ENV=test
Run Code Online (Sandbox Code Playgroud)
并且架构已成功加载.
我能找到的最有用的参考资料,这些参考资料帮助我找到解决方案:
| 归档时间: |
|
| 查看次数: |
1447 次 |
| 最近记录: |