简体   繁体   English

当我使用Ruby 1.9和Rails 2.3.4时,flash [:notice]抛出错误

[英]flash[:notice] is throwing error when I use Ruby 1.9 with Rails 2.3.4

The Post pages I just generated using the scaffolding but they are not working When I try to access the New post page it give me the error. 我刚刚使用脚手架生成的帖子页面,但它们不起作用当我尝试访问新帖子页面时,它给了我错误。

Here is My layout code 这是我的布局代码

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

Error that I get when i try to access the page 我尝试访问该页面时收到错误

    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'

Here is the gem list that I am using with ruby 1.9 这是我使用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)

Note: I also downgraded my RubyGems to 1.8.25 as newer was not working with db:create rake command 注意:我还将我的RubyGems降级为1.8.25,因为较新的不使用db:create rake命令

In ruby 1.8 "abc"[0] returns ASCII code of the first character (integer number 97) but in ruby 1.9 it returns string with the first character (string "a") 在ruby 1.8中, "abc"[0]返回第一个字符的ASCII码(整数97)但在ruby 1.9中它返回带有第一个字符的字符串(字符串“a”)

Integer number has method ^ but String doesn't. 整数有方法^但字符串没有。

You can try the following to fix this: 您可以尝试以下方法来解决此问题:

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

This is probably not the best solution (maybe better to patch some method in rails). 这可能不是最好的解决方案(可能更好地修补rails中的某些方法)。

Downgrading the Rails from 2.3.4 to 2.3.18 and rubyGems to 1.8.25 will fix the problem. 将Rails从2.3.4降级到2.3.18并将rubyGems降级到1.8.25将解决问题。 Apparently Ruby 1.9.3 don't go well with 2.3.4 显然Ruby 1.9.3与2.3.4并不顺利

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

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