简体   繁体   中英

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

    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

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")

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).

Downgrading the Rails from 2.3.4 to 2.3.18 and rubyGems to 1.8.25 will fix the problem. Apparently Ruby 1.9.3 don't go well with 2.3.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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