2013-07-24 100 views
-2

编辑:清理这个问题了通过删除不必要的细节语法错误,我不明白

我试图使用数据映射红宝石,但我不断收到这个语法错误,我不知道如何解决它:

user.rb:1: syntax error, unexpected keyword_class, expecting $end 
include DataMapper... 
         ^

user.rb:

require 'data_mapper' 

class User 
    include DataMapper::Resource 

    property :id,   Serial #serial means auto-incrementing PK 
    property :uname,  String, :key=>true 
    property :name,   String 
    property :email,  String 
    property :is_locked, Boolean, :default=>false 
    property :image,  String 
    property :must_change_psw, String, :default=>false 

    property :salt,   String, :accessor=>:private 
    property :hash,   String, :accessor=>:private 

    #returns true if the password provided is correct AND the user is not locked 
    def correct? (pass) 
     return (self.hash==hash(pass,self.salt))&!self.is_locked 
    end 

end 

def hash(secret,salt) 
    return true #for now 
end 
+0

我会下载并安装以前的版本试试 –

+0

试图与红宝石1.9.1,同样的问题 –

回答

1

我发现这个文件保存在一台Mac格式 - 新线被编码为\r而不是\ n。

Ruby似乎不喜欢那样。

要解决它,我用tr '\r' '\n' <user.rb> user.rb