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