I am trying to check if a record is stale and update if it is. Here's my code:
@listing = Listing.where(listing_id: listing['listing_id'])
if @listing.exists?
if @listing.created_at < 7.days.ago # line where error shows
@listing.update(state: listing['state'])
end
end
And I'm getting the following error:
undefined method `updated_at' for #<Listing::ActiveRecord_Relation:0x00007fb3ebabbac0> Did you mean? update_all
Here's my DB record:
<Listing id: 5, listing_id: 188996174, state: "active", created_at: "2018-03-13 20:43:35", updated_at: "2018-03-13 20:46:48">
And my migration:
class CreateListings < ActiveRecord::Migration[5.1]
def change
create_table :listings do |t|
t.integer :listing_id
t.string :state
t.timestamps
end
end
end
Any ideas? Thanks in advance!