【问题标题】:Rails project won't start - error unexpected : expecting $endRails 项目无法启动 - 意外错误:期待 $end
【发布时间】:2012-04-16 16:16:57
【问题描述】:

我想从this git repository 获取 ribbot 的开源代码。我已经下载了 rails 及其必要的 gem,以及 mongo db 并“安装了包”。 但是在运行项目时出现以下错误。

如何解决?

/Library/Ruby/Gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load': /Users/hansarijanto/Desktop/Impact/ribbot/config/initializers/ session_store.rb:4:

语法错误,意外 ':',期待 $end (SyntaxError) ...sion_store :cookie_store, key: '_ribbot_session', :domain =>...

我已经跟踪了带有语法错误的文件 session_store.rb 目前看起来像这样:

# Be sure to restart your server when you modify this file.

# See environment specific overrides also
Ribbot::Application.config.session_store :cookie_store, key: '_ribbot_session', :domain => :all, :expire_after => 10.years

# Use the database for sessions instead of the cookie-based default,
# which shouldn't be used to store highly confidential information
# (create the session table with "rails generate session_migration")
# Ribbot::Application.config.session_store :active_record_sto

【问题讨论】:

    标签: ruby-on-rails ruby


    【解决方案1】:

    您使用的是 Ruby 1.8,但在您的 config/initializers/session_store.rb 中使用了 Ruby 1.9 hash syntax。以下sn-p:

    key: '_ribbot_session'
    

    应该是

    :key => '_ribbot_session'
    

    【讨论】:

    • 我已经尝试过了,但在运行时仍然出现此错误:/Library/Ruby/Gems/1.8/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load ':/Users/hansarijanto/Desktop/Impact/ribbot/config/initializers/wrap_parameters.rb:8:语法错误,意外':',期待kEND(SyntaxError)wrap_parameters格式:[:json]
    • @HansAdiputraArijanto 这是一个完全不同的文件,但可能是同一个问题。检查该文件,看看它是否也使用 Ruby 1.9 哈希语法,如果是,则以与我的答案相同的方式替换它。
    • 如果我将我的 ruby​​ 更新到 1.9 会更有益吗?
    • 抱歉,我好像在运行 1.8.7,这显然是不可取的。你对我应该如何更新我的版本有什么建议吗?我想避免版本冲突。
    • @HansAdiputraArijanto 查看rbenvRVM,这是管理Ruby 版本的两个流行工具。
    【解决方案2】:

    因为 ribbot 使用的是 ruby​​ 1.9,所以您应该更新您的 ruby​​ 版本,而不是更改代码以使其工作,当前的 ruby​​ 版本是 1.9.3 http://www.ruby-lang.org/en/downloads/

    安装说明

    • 如果您使用的是 mac 操作系统:

    http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac

    • 如果您使用的是 ubuntu linux:

    http://www.rubyinside.com/how-to-install-ruby-1-9-2-and-rails-3-0-on-ubuntu-10-10-4148.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-15
      • 2013-04-30
      • 1970-01-01
      • 1970-01-01
      • 2012-02-10
      • 1970-01-01
      相关资源
      最近更新 更多