【问题标题】:Rails 3, using mongoid but syntax error gets producedRails 3,使用 mongoid 但会产生语法错误
【发布时间】:2011-06-02 07:42:27
【问题描述】:

在我的开发环境(Windows 7,Ruby1.9.2p180)中,一切都可以正常工作。

但是,在使用 rvm 的 Ubuntu 10.04、Ree 1.8.7 的生产环境中,会产生以下错误。 (我正在使用passenger-apache-module 来运行应用程序。)

/home/randomapp/public_html/app/models/article.rb:14: syntax error, unexpected ':', expecting kEND field :user_id, type: Hash ^ 
/home/randomapp/public_html/app/models/article.rb:15: syntax error, unexpected ':', expecting kEND field :username, type: String ^ 
/home/randomapp/public_html/app/models/article.rb:16: syntax error, unexpected ':', expecting kEND field :title, type: String ^ 
/home/randomapp/public_html/app/models/article.rb:17: syntax error, unexpected ':', expecting kEND field :content, type: String ^ 
/home/randomapp/public_html/app/models/article.rb:18: syntax error, unexpected ':', expecting kEND field :display_content, type: String ^ 

这些行的代码如下

  field :user_id, type: Hash
  field :username, type: String
  field :title, type: String
  field :content, type: String
  field :display_content, type: String

假设上面的行在开发中工作正常,你认为这可能是语法解析器的问题吗??? 我该如何解决这个问题?

【问题讨论】:

    标签: ruby-on-rails apache2 passenger mongoid


    【解决方案1】:

    您使用的是 1.9.2 哈希语法。如果你想同时在 1.9.2 和 1.8.7 上运行,那么试试这个:

    field :user_id, :type => Hash
    field :username, :type => String
    field :title, :type => String
    field :content, :type => String
    field :display_content, :type => String
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-18
      相关资源
      最近更新 更多