简体   繁体   English

如何在Ruby 2.0上运行Ruby on Rails 3

[英]How to run Ruby on Rails 3 with ruby 2.0

Is there an easy fix, how I could continue an old rails 3-0.20 installation under ruby 2.0? 有一个简单的解决方法,如何在ruby 2.0下继续安装旧的rails 3-0.20?

The first error, caused by this line: 由此行引起的第一个错误:

<%= stylesheet_link_tag :all %>

is

ActionView::Template::Error (no implicit conversion of nil into String):

An upgrade of the rails version would be the best, but unfortunately it is not possible in my case. 升级Rails版本是最好的,但是不幸的是,在我看来,这是不可能的。

在application.rb结尾修复以下行的问题

ActionController::Base.config.relative_url_root = ''

I ran into the same issue. 我遇到了同样的问题。 After drilling down into the stylesheet_link_tag method, I found that the issue comes from here 深入研究stylesheet_link_tag方法后,我发现问题出在这里

# actionpack-3.0.20/lib/action_view/helpers/asset_tag_helper.rb:749
if has_request && include_host && !source.start_with?(controller.config.relative_url_root)

The problem is String#starts_with? 问题是String#starts_with? . In 1.9.3, that method will handle a nil as an input. 在1.9.3中,该方法将把nil作为输入。 2.0.0 does not allow that. 2.0.0不允许这样做。

ruby-1.9.3> 'whatever'.start_with? nil
=> false

ruby-2.0.0> 'whatever'.start_with? nil
TypeError: no implicit conversion of nil into String

It's probably also true that later versions of Rails set the value to '' if it's not set to prevent this issue. 如果未将Rails的更高版本设置为防止发生此问题,则也可能会将其设置为”。 The hotfix mentioned above does fix the issue, but the root cause is differences between 1.9.3 and 2.0.0. 上面提到的修复程序确实解决了此问题,但根本原因 1.9.3和2.0.0之间存在差异。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM