How do I get a custom Rake task to run in Sinatra?

narzero

*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.

UPDATE

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)
Maurício Linhares

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Ruby on Rails: How do I run an automated rake task on Heroku

From Dev

How do I skip a rake task

From Dev

how to run a custom rake task from mina deployment script

From Dev

How do I get Active Record query that works in Rails console working in a rake task?

From Dev

How do I pass environmental variables to a Rake task invoked from another Rake task?

From Dev

How do I execute a "rake task" after every db:reset

From Dev

How do I programmatically extract a rake task's description?

From Dev

How do I execute a "rake task" after every db:reset

From Dev

Get output of previously run rake task

From Dev

How do I run a Ruby app using Sinatra as a service

From Dev

How do I access sinatra settings in custom extension specs?

From Dev

How do I access sinatra settings in custom extension specs?

From Dev

How do I structure a custom task and how do I get pretty output?

From Dev

How do I run multiple rake tasks at once?

From Dev

How do I run Rails/Rake from another directory?

From Dev

How do I run multiple rake tasks at once?

From Dev

How to run a rake task by command line in rails

From Dev

How to run a rake task depending on environment?

From Dev

How to run a rake task on jenkins with string parameters?

From Dev

How do I schedule a task to run once?

From Dev

How do I make a custom-created windows schedule task not run in background?

From Dev

Rake task identifying the environment as development ruby and sinatra

From Dev

How do you run a rake task at midnight of every single time zone?

From Dev

How do I get tab completion to work with 'rake'?

From Dev

How do I get a .bat file to run in Task Scheduler at PC Startup?

From Dev

How do I get task scheduler to run my batch file minimized

From Dev

Can I run a rake task to simulate sidekiq running?

From Dev

How do I create a console command (rake task) in Yii2?

From Dev

How do I delete action cache from a rake task in rails 4

Related Related

  1. 1

    Ruby on Rails: How do I run an automated rake task on Heroku

  2. 2

    How do I skip a rake task

  3. 3

    how to run a custom rake task from mina deployment script

  4. 4

    How do I get Active Record query that works in Rails console working in a rake task?

  5. 5

    How do I pass environmental variables to a Rake task invoked from another Rake task?

  6. 6

    How do I execute a "rake task" after every db:reset

  7. 7

    How do I programmatically extract a rake task's description?

  8. 8

    How do I execute a "rake task" after every db:reset

  9. 9

    Get output of previously run rake task

  10. 10

    How do I run a Ruby app using Sinatra as a service

  11. 11

    How do I access sinatra settings in custom extension specs?

  12. 12

    How do I access sinatra settings in custom extension specs?

  13. 13

    How do I structure a custom task and how do I get pretty output?

  14. 14

    How do I run multiple rake tasks at once?

  15. 15

    How do I run Rails/Rake from another directory?

  16. 16

    How do I run multiple rake tasks at once?

  17. 17

    How to run a rake task by command line in rails

  18. 18

    How to run a rake task depending on environment?

  19. 19

    How to run a rake task on jenkins with string parameters?

  20. 20

    How do I schedule a task to run once?

  21. 21

    How do I make a custom-created windows schedule task not run in background?

  22. 22

    Rake task identifying the environment as development ruby and sinatra

  23. 23

    How do you run a rake task at midnight of every single time zone?

  24. 24

    How do I get tab completion to work with 'rake'?

  25. 25

    How do I get a .bat file to run in Task Scheduler at PC Startup?

  26. 26

    How do I get task scheduler to run my batch file minimized

  27. 27

    Can I run a rake task to simulate sidekiq running?

  28. 28

    How do I create a console command (rake task) in Yii2?

  29. 29

    How do I delete action cache from a rake task in rails 4

HotTag

Archive