编辑通过删除不必要的详细信息来清除此问题
我正在尝试将数据映射器与ruby一起使用,但我一直收到此语法错误,我不知道如何修复它:
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 :(得分:1)
我发现此文件以Mac格式保存 - 新行编码为\r
而不是\ n。
Ruby似乎不喜欢这样。
为了解决这个问题,我使用了tr '\r' '\n' < user.rb > user.rb