Run ruby script on page load

I’m developing a relatively static website with just one dynamic script
‘rub-this.rb’ that is making use of the Nokogiri gem. This script also
uses the JSON gem to convert the output into JSON.

My question is, is it possible for me to load the script on page load or
do I have to make use of say Rails or the Sinatra framework? I don’t
mind using either of the two but it does make my task rather cumbersome
especially since there’s no back end database as such and the only
script running would be the run-this file.

On Wed, Jan 8, 2014 at 5:56 PM, Siddhart Mantri
[email protected]wrote:


Posted via http://www.ruby-forum.com/.

Do you mean when the page is loaded by the browser? At that stage, yes,
I’d
just use AJAX call to a tiny Sinatra ditty to wrap your script.

Subject: Run ruby script on page load
Date: gio 09 gen 14 12:56:57 +0100

Quoting Siddhart Mantri ([email protected]):

I’m developing a relatively static website with just one dynamic script
‘rub-this.rb’ that is making use of the Nokogiri gem. This script also
uses the JSON gem to convert the output into JSON.

My question is, is it possible for me to load the script on page load or
do I have to make use of say Rails or the Sinatra framework? I don’t
mind using either of the two but it does make my task rather cumbersome
especially since there’s no back end database as such and the only
script running would be the run-this file.

Have you looked into Webrick? It is the webserver that is included in
MRI. There is pretty little documentation, but once you learn your way
around, I believe you can solve your problem with just a few lines of
code, without having to carry around huge infrastructures with even
huger dependences. Of course, it is not the fastest webserver
available, but if you expect not too much traffic it works pretty
well.

Carlo

Another alternative would be use Rack

http://net.tutsplus.com/tutorials/exploring-rack/
http://rubylearning.com/blog/a-quick-introduction-to-rack/

Saji N Hameed,
ARC-ENV, Center for Advanced Information Science and Technology,
University of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,
Japan

Tel: +81242 37-2736
Fax:+81242 37-2760
email: [email protected]
url: http://enformtk.u-aizu.ac.jp
bib: http://www.researcherid.com/rid/B-9188-2009
code: https://github.com/sajinh

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs