*I want to get a custom Rake task to run in my Sinatra app but I keep getting rake aborted!
Don't know how to build task 'greet'
.
Here's the custom Rake task (greet.rake
) for testing purpose:
task :greet do
puts "Hello!"
end
I've put the greet.rake
in ./lib/tasks
(Rails). I'm guessing Rake can't find the correct directory for the file.
How do I get a custom Rake task to run in Sinatra?
I'm using Ruby 2.0.0 and Sinatra 1.4.4.
The Rakefile now looks like this:
require "./app"
require "sinatra/activerecord/rake"
require "./lib/tasks"
When using:
rake greet
I get:
rake aborted!
cannot load such file -- ./lib/tasks
/Users/*/.rvm/gems/ruby-2.0.0-p247@global/gems/activesupport- 4.0.1/lib/active_support/dependencies.rb:229:in `block in require'
/Users/*/.rvm/gems/ruby-2.0.0-p247@global/gems/activesupport- 4.0.1/lib/active_support/dependencies.rb:214:in `load_dependency'
/Users/*/.rvm/gems/ruby-2.0.0-p247@global/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require'
/Users/*/Dropbox/Development/Sinatra/sinatra-mp-experiment/Rakefile:3:in `<top (required)>'
(See full trace by running task with --trace)
Create a Rakefile
at your Sinatra app's top directory, require the file that contains this task you want to use and you should be good to go.
Edit:
A simple solution is changing your Rakefile
to:
require "./app"
require "sinatra/activerecord/rake"
Dir.glob('lib/tasks/*.rake').each { |r| load r}
Now any .rake
file under lib/tasks
will be loaded.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With