rspec - Rails - Call a method from within a string -
i trying call method i've defined within string, passed parameter method, so:
existing_size = self.exchange_rates.where("? < date_valid", :time).size
the method is:
def date_valid date = date.today if(time.now.hour >= hour) date += 1.day end date end
however, error:
activerecord::statementinvalid: pg::undefinedcolumn: error: column "date_valid" not exist line 1: ...xchange_rates"."prediction_id" = $1 , ('time' < date_valid...
it seems though have time
attribute , date_valid
method swapped in where
call. of course assuming time
is, in fact, column in exchange_rates
table. following should work you.
existing_size = self.exchange_rates.where("time < ?", date_valid).count
i've used count
instead of size
because count
calculation in database, while size
in memory on returned exchanged_rates
relation.
Comments
Post a Comment