Lior Elrom
Lior Elrom

Reputation: 20912

Join multiple conditions using Where method in Rails ActiveRecord

I'm trying to join two different conditions on an Active Record Database. Usually, I'll join them using a comma (,) or AND, but in this case, putting a comma or AND between conditions returns an error.

I wonder how to join those conditions together in one statement (I'm using rails 4):

MyTable.where("created_at < ?", Time.now - 86400) # 86400 represent a day

MyTable.where(my_column: my_variable)

Upvotes: 0

Views: 706

Answers (1)

usha
usha

Reputation: 29369

MyTable.where("created_at < ? AND my_column = ?", Time.now - 86400, my_variable)

Upvotes: 1

Related Questions