2012-04-27 114 views
2

所以,我遇到了這個問題(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中/ ruby​​1.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 
+0

你可以用RVM管理烏爾紅寶石版本 – 2012-04-27 02:29:52

+0

@Kit何如前所述,我試圖通過RVM更改默認的版本,它的工作原理,但我仍然有同樣的問題。 「rvm list default」返回「ruby-1.9.3-p194」。 – Bryan 2012-04-27 02:40:48

回答

3

所以我終於弄明白。這就是我所做的。

首先,解決我卸載紅寶石1.8。從那以後,我試圖運行軌小號再次得到了以下錯誤:

bash: /usr/local/bin/rails: /usr/bin/ruby1.8: bad interpreter: No such file or directory 

當我檢查在/ usr/local/bin目錄/軌腳本,我看到它包括在/ usr/bin中/ ruby​​1。頂部有8。嘗試噸不同的東西后得到它的工作,只有工作是卸載紅寶石,RubyGems的,導軌和RVM,並重新安裝所有這些事情(我不得不這樣做幾次......終於它的工作一次)。

您可以嘗試下面列出的內容,瞭解它是否適​​用於您: http://fatal-errors.com/ubuntu-10-ruby-1-9-rails-3-not-working-solved/99008

0

編輯您的終端配置文件(在〜/ .bashrc,〜/ .zshrc等),並確保包含Ruby 1.9的目錄在通道中出現在/ usr/bin之前變量。一般來說,修改/ usr/bin是不好的,因爲這裏的東西通常是系統依賴關係。

+0

感謝您的答案,但它似乎並沒有工作。這兩個文件是空的,並且將Ruby 1.9目錄添加到PATH的前面(通過終端)也沒有工作。 – Bryan 2012-04-27 02:37:01

+0

這兩個文件不一定是你的shell配置。你在用什麼外殼? – Max 2012-04-27 02:44:41

+0

我正在使用bash。 – Bryan 2012-04-27 02:47:49