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?
-
4Can't you make a class out of it, then load it as a part of environment and use?Sergio Tulentsev– Sergio Tulentsev2012-05-06 16:26:10 +00:00Commented May 6, 2012 at 16:26
-
If you don't want to do @SergioTulentsev solution you can always run the script using exec mentalized.net/journal/2010/03/08/… (but his solution is better)Andión– Andión2012-05-06 16:37:36 +00:00Commented May 6, 2012 at 16:37
-
I see that I have little basis in rails, the best would be to create a method in the helper and then run it correct? EDIT: I just saw that helpers only works for views! And for controllers?Anthony Sewr– Anthony Sewr2012-05-06 16:56:09 +00:00Commented May 6, 2012 at 16:56
-
@AnthonySewr And for controllers... Look at my answervaratis– varatis2012-05-06 18:03:11 +00:00Commented May 6, 2012 at 18:03
Add a comment
|
2 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.