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?

McGweeezy
  • 3
  • 4

1 Answers1

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!

Community
  • 1
  • 1
Sudeep Juvekar
  • 4,898
  • 3
  • 29
  • 35
  • that link you left "how to integrate a standalone python script into a Rails application" is exactly what i was looking for. thank you – McGweeezy Feb 14 '14 at 15:55
  • 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 – McGweeezy Feb 14 '14 at 16:08