0

I would like to create a Javascript file in my RoR project that act like a tasks. I know that for a Ruby file, you write your code in lib/tasks/my_task.rake and run your task by typing rake:name_of_the_task in your console.

I would like to do the same process but in Javascript, is anyone having a tutorial or could explain me how it works ? Can I insert javascript in my rake file ?

Thanks !

Damien Compère
  • 219
  • 1
  • 3
  • 16
  • You want Ruby to run a Javascript file through node.js or something? – TKoL Dec 17 '19 at 14:01
  • no specially with node.js just that the script act like a task in Ruby – Damien Compère Dec 17 '19 at 14:04
  • You could build an AJAX "task" but it would only be able to do what ever you can do through a browser request. If that works then you could create the AJAX and then trigger it using curl through rake? Maybe? – Beartech Dec 17 '19 at 14:35
  • 1
    There is one question that is always above all questions: WHY? – BroiSatse Dec 17 '19 at 15:44
  • Because I need to use an API to download some informations. – Damien Compère Dec 17 '19 at 16:03
  • What kind of API? Is it only available to Javascript? What is the purpose of the task? Does it update data on the server? I assume it's only to be run occasionally by you, the developer? But, no, you can't insert javascript into a Rake file. Maybe have a look at [How to run Javascript files from the command line](https://stackoverflow.com/questions/12659778/is-it-possible-to-run-javascript-files-from-the-command-line) – lurker Dec 17 '19 at 19:42
  • The purpose of my task is to grab documents related to some account to send them to my user, it doesn't update any data on my server as I pass throught the API to get the documents. It's supposed to run everyday, well maybe I could use HTTParty to make some call, would it be better ? – Damien Compère Dec 18 '19 at 09:02

0 Answers0