Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run ruby script in rails

I made a script in ruby ​​and now I need to run it in a rails application. I'm a little lost, but I have a controller, and wanted through a GET /service /:id returns the result of this script. How can I do this?

like image 918
Anthony Sewr Avatar asked Dec 13 '25 15:12

Anthony Sewr


1 Answers

By the comments, it seems like you want to make this into a method you can call from your controller.

Simple.

Define the method in the corresponding Model for the Controller you're calling it from (or whatever Model you wish to define the method in) and then call it from the Controller.

Say you have a ScriptRunner model, and you want to call this from the show action of some controller.

In your ScriptRunner model, simply do

def runscript(id)
...
end

and in your controller, do

def show
  ScriptRunner.runscript(params[:id])
  @service = Service.find_by_id(params[:id])
end

..or whatever you want it to do.

like image 181
varatis Avatar answered Dec 15 '25 14:12

varatis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!