所以,我遇到了這個問題(Syntax error when creating a Rails model),其中有與我相似的錯誤。我從中推斷出我的問題是使用Ruby 1.8而不是1.9。我嘗試卸載寶石,並按照其中一個答案中所述更新rubygems,但這並未解決問題。我也嘗試通過rvm設置默認的紅寶石爲1.9 - 它的工作原理,但它不能解決問題。運行rails服務器時出錯 - 如何更改rubygem環境的默認ruby?
當我運行 「寶石ENV」 我得到如下:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.23
- RUBY VERSION: 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/lib/ruby/gems/1.8
- /home/owner/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
在USR/bin中我有一個 「紅寶石」,這是一個符號鏈接到usr/bin中/ ruby1.9.1。
基本上,我需要知道如何改變紅寶石在這裏被使用(至少我認爲這將解決我的問題)。
我的操作系統是Linux Mint的12 Rails的--version返回 「的Rails 3.2.3」
我的全誤差小於(從運行 「軌道的」 在項目目錄):
=> 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
/usr/lib/ruby/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load': /media/Windows/Users/Owner/Projects/rails_projects/sample_app/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_sample_app_session'
^
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:236:in `load_dependency'
from /usr/lib/ruby/gems/1.8/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:245:in `load'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:588
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:587:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/engine.rb:587
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `instance_exec'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:30:in `run'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:55:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `each'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/initializable.rb:54:in `run_initializers'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/application.rb:136:in `initialize!'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `send'
from /usr/lib/ruby/gems/1.8/gems/railties-3.2.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /media/Windows/Users/Owner/Projects/rails_projects/sample_app/config/environment.rb:5
from /media/Windows/Users/Owner/Projects/rails_projects/sample_app/config.ru:4:in `require'
from /media/Windows/Users/Owner/Projects/rails_projects/sample_app/config.ru:4
from /usr/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /media/Windows/Users/Owner/Projects/rails_projects/sample_app/config.ru:1:in `new'
from /media/Windows/Users/Owner/Projects/rails_projects/sample_app/config.ru:1
我的Gemfile是:
source 'https://rubygems.org'
gem 'rails'
gem 'bootstrap-sass'
gem 'tilt'
gem 'execjs'
gem 'therubyracer', :platforms => :ruby
group :development do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails'
gem 'guard-rspec', '0.5.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'
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.0'
group :test do
gem 'rspec-rails'
gem 'capybara', '1.1.2'
# System-dependent gems# Test gems on Windows
group :test do
gem 'rspec-rails'
gem 'capybara', '1.1.2'
gem 'rb-fchange', '0.0.5'
gem 'rb-notifu', '0.0.4'
end
gem 'guard-spork', '0.3.2'
gem 'spork', '0.9.0'
end
group :production do
gem 'pg', '0.12.2'
end
PATH:
echo $PATH /usr/bin/rubycurrent:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
「的紅寶石」 的回報:
/usr/bin/rubycurrent/ruby
你可以用RVM管理烏爾紅寶石版本 – 2012-04-27 02:29:52
@Kit何如前所述,我試圖通過RVM更改默認的版本,它的工作原理,但我仍然有同樣的問題。 「rvm list default」返回「ruby-1.9.3-p194」。 – Bryan 2012-04-27 02:40:48