0

I would like to be able to click an "Alert" button on my rails application that then calls python to run a specific alert script.

My specific question is how do I get the click event to call the python script?

1
  • What you tried so far? Commented Feb 14, 2014 at 15:29

1 Answer 1

0

Check this SO post: Call python script from ruby

ruby provides a variety of methods, exec, system that all take the path to the ,py file along with arguments. Something like

result = exec("python /path/to/script/script.py params")

Or

system 'python /path/to/script/script.py', params1, params2

Or even backquotes

`python /path/to/script/script.py foo bar`

Now, the question is where to put this? I am assuming you have a controller that handles clicks, and it is this controller where you put this code. Check this link out How to integrate a standalone Python script into a Rails application?

Now details depend a lot on your python script. By 'alert script', do you mean a Javascript alert() dialog, a flash msg or anything else? It's always a good idea to refactor your python code to return a string result and the use that in ruby-on-rails. Even better, as far as possible, write the alert-creating-script in ruby itself! It might not be possible in a 3rd-party library setting, but for a simple stand-alone script, it's worth the effort!

Sign up to request clarification or add additional context in comments.

2 Comments

that link you left "how to integrate a standalone python script into a Rails application" is exactly what i was looking for. thank you
I am working on a project that sends alerts out to gps tracking systems of people doing land navigation. The alert would be an arbitrary message sent through a number of xbee devices to the user relaying a message like "inclement weather," or "stay on the path." I would like the user to be able to click the "Alert" button from the webpage that initiates the whole process. So by 'alert script' it's just the name of my .py file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.