-2

edit: cleaned this question up by removing unneccessary detail

I'm trying to use data mapper with ruby, but I keep getting this syntax error, and I have no idea how to fix it:

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
4

1 回答 1

1

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

鲁比似乎不喜欢那样。

为了修复它,我使用了tr '\r' '\n' < user.rb > user.rb

于 2013-07-28T08:06:11.223 回答