3

我已经使用本指南在我的 MacOS X 中安装了 RoR http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/

这是我的版本:

$ ruby --version
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
$ rails --version
Rails 3.2.3
$ gem --version
1.8.23

我无法运行我的应用程序,因此我使用本教程搜索并修改了 Gemfile:http ://ruby.railstutorial.org/ruby-on-rails-tutorial-book

现在这是我的 Gemfile:

source 'https://rubygems.org'

gem 'rails', '3.2.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

group :development do
  gem 'sqlite3', '1.3.5'
end

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '3.2.4'
  gem 'coffee-rails', '3.2.2'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platform => :ruby

  gem 'uglifier', '1.2.3'
end

gem 'jquery-rails', '2.0.0'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'

当我使用运行应用程序时

rails server

我懂了:

=> Booting WEBrick
=> Rails 3.2.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load': /Users/giacomo/websrc/rubyrails-app/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_rubyrails-app_session'
                              ^
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /Library/Ruby/Gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:588
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:587:in `each'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:587
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `run_initializers'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `send'
    from /Library/Ruby/Gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/giacomo/websrc/rubyrails-app/config/environment.rb:5
    from /Users/giacomo/websrc/rubyrails-app/config.ru:4:in `require'
    from /Users/giacomo/websrc/rubyrails-app/config.ru:4
    from /Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
    from /Library/Ruby/Gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
    from /Users/giacomo/websrc/rubyrails-app/config.ru:1:in `new'
    from /Users/giacomo/websrc/rubyrails-app/config.ru:1

我该如何解决这个问题?

4

2 回答 2

4

通过使用 Ruby 1.9.x 而不是 1.8.7。

或者通过打开/Users/giacomo/websrc/rubyrails-app/config/initializers/session_store.rb和替换:

key: '_rubyrails-app_session'

和:

:key => '_rubyrails-app_session'

并打开/Users/giacomo/websrc/rubyrails-app/config/initializers/wrap_parameters.rb和更换:

wrap_parameters format: [:json]

和:

wrap_parameters :format => [:json]
于 2012-04-27T13:29:09.033 回答
2

发生错误是因为新的 ruby​​ 具有另一种哈希语法。您使用的教程已过时,我建议您尝试一下:http ://railsapps.github.com/installing-rails.html 这是我能找到的最好的。而且它还在不断更新。

在您的情况下,您只需要安装新版本的 ruby​​,然后重新安装 rails。

于 2012-04-27T13:41:12.870 回答