Run ruby ​​script in rails

I made a script in ruby ​​and now I need to run it in a rails application. I am a bit lost, but I have a controller, and I would like to get GET / service /: id returns the result of this script. How can i do this?

+3
source share
2 answers

According to the comments, it seems that you want to do this in a way that you can call from your controller.

Simple

Define the method in the appropriate model for the controller from which you are calling it (or any other model that you want to define in this method), and then call it from the controller.

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

ScriptRunner

def runscript(id)
...
end

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

.. .

+4

, .

, , ruby ​​ script

def get
  @results = system "ruby your_ruby_script.rb" 
end
+2

All Articles