A scope allows you to specify an ARel query that can be used as a method call to the model (or association objects).
1 2 3 4 5 6 |
|
There’s a problem if we try using a scope for a relative date, though.
1 2 3 |
|
This code gets evaluated when the server is started, and the output of Date.today
is stored in the scope.
That scope is equivalent to the following:
1 2 3 4 5 |
|
The date is hardcoded in there, and will not be changed until the scope is re-evaluated. This typically happens only when the server is restarted.
To get around this problem, use a lambda when defining date (or time) based scopes. This will force the evaluation of the scope each time it is called.
1 2 3 |
|