2012-09-22 115 views
0

每当我尝试并从datamapper中计数返回的记录时,它总是返回0,无论是否有用户。Ruby Datamapper .count总是返回0

User.count(:username=>params[:username]) 

class User 
    include DataMapper::Resource 

    property :id, Serial 
    property :username, String, unique_index: true, required: true, length: 3..32 
    property :password, String, required: true, length: 5..64 
    property :email, String, unique_index: true, required: true, format: :email_address 

end 
+0

你100%肯定有一个在你的数据库中的用户?您可以提供更多的代码片段的上下文吗? – Makoto

+0

@Makoto这里肯定有一个用户,因为如果我删除if语句,那么所有其他代码都会执行得很好,这涉及从数据库获取详细信息。至于更多的代码,我刚刚更新了它。 – DCWill

回答

0

你可以尝试User.all(:username=>params[:username])控制台 ,然后尝试

User.count(:username=>params[:username])为ENV