質問

PG::DatatypeMismatch: ERROR: argument of WHERE must be type boolean, not type integer LINE 1: SELECT "timecards".* FROM "timecards" WHERE (user_id) ORDE...

This in in my controller:

def index

 @users = User.find(:all)   
 @timecards = Timecard.find(:all, :conditions => "user_id", :order => "checkin_time ASC")

 @worklogs = Timecard.find(:all, :conditions => {:user_id=>current_user}, :order => "checkin_time ASC")
 @jobs = Job.find(:all, :conditions =>"id") 

end
役に立ちましたか?

解決 2

Better would be

Timecard.where(user_id: current_user.id).order(:checkin_time)

他のヒント

The problem is right here:

@timecards = Timecard.find(:all, :conditions => "user_id", :order => "checkin_time ASC")
# ----------------------------------------------^^^^^^^^^

If you give it a String in the :conditions then that String goes straight into the SQL and

where (user_id)

doesn't make any sense to PostgreSQL because user_id is an integer column. You're going to have the same problem with Job.find(:all, :conditions => "id"). I have no idea what either of those :conditions should be though.

I also suspect that you're developing on top of SQLite since you (presumably) didn't find this problem in your development or testing environments. If you're deploying on top of PostgreSQL then you really should develop and test on top of PostgreSQL. You should always develop, test, and deploy using the same stack, there's no such thing as database portability (unless you do it yourself) and no ORM will protect you from database differences.

I'd also recommend that you move away from the old Rails2-style find(:all, ...) stuff in favor of a more modern .where(...).where(...).order(...) approach.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top