Currently, in my controller I am assigning values to a variable like so:
@tasks = @list.tasks.where(:importance => 'high', :active => true).search(params[:search])
What I’m wondering is if there is a way with .where or any other way to use a model method for selection selection. I have a model method that returns a string representing a relative due date:
def due
if self.due_date < Date.today + 2.days
return 'now'
elsif self.due_date < Date.today + 1.week
return 'soon'
else
return 'later'
end
end
I don’t want to store this .due value in the database, as it’ll be changing constantly based off what the date is. But what I, in theory, would want to do is something like this in my controller for selection:
@tasks = @list.tasks.where(:importance => 'high', :active => true, :due => 'now).search(params[:search])
But this will not work as .due is not in the database. Should I be doing this with scopes? Anyway, appreciate the help.
You could do scopes:
Alternatively, you could just use your class method like so: