Run ruby script in rails

ruby-on-rails, ruby-on-rails-3

Solution

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.

Problem

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?

Original source