简体   繁体   中英

new-style hash argument available error in Ruby 1.9.3

I just moved a project to another server and seem to be having problems related to the new new hash argument available since Ruby 1.9.2. When I run rails s I get the following error

Exiting
/usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load': /var/www/myapp/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError) ...sion_store :cookie_store, key: '_myapp_session'
                          ^
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/engine.rb:556
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/engine.rb:555:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/engine.rb:555
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:30:in `run'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:55:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/application.rb:96:in `initialize!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `send'
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /var/www/myapp/config/environment.rb:5
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:223:in `load_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:240:in `require'
from /var/www/myapp/config.ru:4
from /usr/lib/ruby/gems/1.8/gems/rack-1.3.4/lib/rack/builder.rb:51:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/rack-1.3.4/lib/rack/builder.rb:51:in `initialize'
from /var/www/myapp/config.ru:1:in `new'
from /var/www/myapp/config.ru:1

The Error is referencing the following line

 Myapp::Application.config.session_store :cookie_store, key: '_myapp_session'

I really don't think the above line of code is the issue. If I remove key: '_myapp_session' or revert it back to the Ruby 1.8.X style I just get the next hash argument error.

I the server I moved to originally had Ruby 1.8.7 running on the server. I have updated ruby to 1.9.3. When I run ruby -v I get ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]

I'm not sure why I'm still having the hash issue. Has anyone ran into similar problems?

You may need to check paths, it appears that it is using the rails executable from the 1.8 ruby tree. When you upgrade, you may need to reinstall gems.. This situation is one reason rvm is the preferred way to install ruby.

you should post the code you're suspecting guilty, it's hard to answer with so little clue.

One gotcha about the new style is that you can only use it if ALL the keys on your hash are symbols, this may be the problem.

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