How do I access a Rails model in a rake file outside of rake tasks?
To access Rails models in a rake task, you specify :environment
as a dependency. But what if you want to have a dynamic description of your task and they depend on some database date. For example:
end_date = Foo.end_date # the model foo provides some end date
desc "Do something after #{end_date}"
task bar: :environment do
...
end
I tried Rake::Task[:environment].invoke
but get it Don't know how to build task 'environment'
.
+3
source to share
No one has answered this question yet
Check out similar questions: