Question

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
Was it helpful?

Solution

I found out that this file was saved in a Mac format - new lines were encoded as \r instead of \n.

Ruby doesn't seem to like that.

To fix it I used tr '\r' '\n' < user.rb > user.rb

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top