2

所以我遇到了这个问题(创建 Rails 模型时出现语法错误),它有一个类似于我的错误。我从中推断出我的问题是使用 Ruby 1.8 而不是 1.9。我尝试按照其中一个答案中的说明卸载 gem 并更新 ruby​​gems,但这并没有解决问题。我还尝试通过 rvm 将默认 ruby​​ 设置为 1.9 - 它可以工作,但不能解决问题。

当我运行“gem 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 中,我有一个“ruby”,它是 usr/bin/ruby1.9.1 的符号链接。

基本上,我需要知道如何更改这里使用的红宝石(至少我认为这会解决我的问题)。

我的操作系统是 Linux Mint 12。Rails --version 返回“Rails 3.2.3”

我的完整错误如下(来自在项目目录中运行“rails s”):

=> 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

我的宝石文件是:

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

小路:

echo $PATH /usr/bin/rubycurrent:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/用户/游戏

“哪个红宝石”返回:

/usr/bin/rubycurrent/ruby
4

2 回答 2

3

所以我终于弄明白了。这就是我所做的。

首先,为了排除故障,我卸载了 ruby​​ 1.8。之后我再次尝试运行rails s并得到以下错误:

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

当我检查/usr/local/bin/rails脚本时,我看到它在顶部包含/usr/bin/ruby1.8 。在尝试了很多不同的方法让它工作之后,唯一有效的方法是卸载 ruby​​、rubygems、rails 和 rvm,然后重新安装它们(我不得不这样做几次......最后它工作了一次)。

您可以尝试下面列出的内容,看看它是否适合您: http: //fatal-errors.com/ubuntu-10-ruby-1-9-rails-3-not-working-solved/99008

于 2012-04-27T18:58:05.930 回答
0

编辑您的终端配置文件(~/.bashrc、~/.zshrc 等)并确保包含 ruby​​ 1.9 的目录出现在 /usr/bin 之前的路径变量中。一般来说,修改 /usr/bin 是不好的,因为这里的东西通常是系统依赖。

于 2012-04-27T02:29:08.873 回答