【问题标题】:flash[:notice] is throwing error when I use Ruby 1.9 with Rails 2.3.4当我将 Ruby 1.9 与 Rails 2.3.4 一起使用时,flash[:notice] 抛出错误
【发布时间】:2016-10-22 22:01:13
【问题描述】:

我刚刚使用脚手架生成的帖子页面但它们不起作用当我尝试访问新帖子页面时,它给了我错误。

这是我的布局代码

    <p style="color: green"><%= flash[:message] %></p>
    <%= yield %>

我在尝试访问页面时遇到的错误

    Processing PostsController#new (for 127.0.0.1 at 2016-10-23 02:45:19) [GET]
    Rendering template within layouts/posts
    Rendering posts/new

 ActionView::TemplateError (undefined method `^' for "4":String) on   line #12 of app/views/layouts/posts.html.erb:
    9: </head>
   10: <body>
   11: 
   12:p style="color: green"><%= flash[:message] %></p>
   13:   
   14: <%= yield %>
   15: 

app/views/layouts/posts.html.erb:12
app/controllers/posts_controller.rb:29:in `new'
<internal:prelude>:10:in `synchronize'
/home/atta/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
/home/atta/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
/home/atta/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

这是我在 ruby​​ 1.9 中使用的 gem 列表

    actionmailer (2.3.4)
    actionpack (2.3.4)
    activerecord (2.3.4)
    activeresource (2.3.4)
    activesupport (2.3.4)
    bigdecimal (1.1.0)
    bundler-unload (1.0.2)
    executable-hooks (1.3.2)
    gem-wrappers (1.2.7)
    io-console (0.3)
    json (1.5.5)
    minitest (2.5.1)
    rack (1.0.1)
    rails (2.3.4)
    rake (0.9.2.2)
    rdoc (3.9.5)
    rubygems-bundler (1.4.4)
    rubygems-update (1.8.25)
    rvm (1.11.3.9)
    sqlite3 (1.3.12)
    sqlite3-ruby (1.3.3)

注意:我也将我的 RubyGems 降级到 1.8.25,因为新版本无法使用 db:create rake 命令

【问题讨论】:

  • 这些版本的 everything 多年来不受支持...出于常识的原因升级
  • 我同意,但我正在准备我的环境来处理一个大型和旧项目
  • 哇,那个版本的 Rails 已经 7 年多了。
  • 我知道 .. 我很尴尬,但我需要设置这个环境才能使旧版 Rails 2.3 应用程序正常工作

标签: ruby-on-rails ruby ruby-on-rails-2


【解决方案1】:

在 ruby​​ 1.8 "abc"[0] 返回第一个字符的 ASCII 码(整数 97) 但在 ruby​​ 1.9 中,它返回带有第一个字符的字符串(字符串“a”)

整数有方法 ^ 但字符串没有。

您可以尝试以下方法来解决此问题:

class String
  def ^(value)
    self.ord ^ value
  end
end

这可能不是最好的解决方案(也许在 rails 中修补某些方法会更好)。

【讨论】:

    【解决方案2】:

    将 Rails 从 2.3.4 降级到 2.3.18 并将 ruby​​Gems 降级到 1.8.25 将解决此问题。显然 Ruby 1.9.3 不适合 2.3.4

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-30
      • 1970-01-01
      • 2011-11-26
      • 1970-01-01
      • 2013-05-11
      • 1970-01-01
      • 2020-10-26
      • 1970-01-01
      相关资源
      最近更新 更多