# Calling a ruby script from javascript

**URL:** <https://www.ruby-forum.com/t/calling-a-ruby-script-from-javascript/145742>\
**Category:** Rails\
**Created:** [August 13, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/calling-a-ruby-script-from-javascript/145742 "2008-08-13T15:13:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [August 13, 2008, 3:13pm UTC](https://www.ruby-forum.com/t/calling-a-ruby-script-from-javascript/145742/1 "2008-08-13T15:13:34Z")

</div>

Here’s the situation: I need to call in an RSS feed to display on a  
page, and am using the jfeed plugin for jquery to parse the feed and  
display it, however, it will only parse a local feed, so in order to  
parse a remote one, you need a proxy.

jfeed itself comes with an example proxy written in PHP, fine, but I’m  
developing a rails-based website.

So here is my question: is there a way I can call the ruby script, in  
a similar way to how you can call a php script, passing a parameter to  
it and then using the result?

The example given by jfeed is: url: ‘proxy.php?url=http://  
[jfhovinne](http://www.hovinne.com/feed/)’

(normally this should be the url of the feed, but if it’s external you  
need the proxy)

If there is no way of doing this, is there a similar way to do it?  
Perhaps using AJAX?

Any help would be gratefully appreciated, I’m a bit stumped.

Thanks,

Mark

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [August 13, 2008, 3:18pm UTC](https://www.ruby-forum.com/t/calling-a-ruby-script-from-javascript/145742/2 "2008-08-13T15:18:16Z")

</div>

On 13 Aug 2008, at 14:13, Mark wrote:

> a similar way to how you can call a php script, passing a parameter to
> 
> Any help would be gratefully appreciated, I’m a bit stumped.

That should work fine. Just add an appropriate controller & action  
that load the specified url for you  
You might find that rails is a bit heavy-weight for that, a mongrel  
handler or something similar might be a better match. Be careful not  
to turn yourself into an open relay.

Fred

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [August 13, 2008, 3:57pm UTC](https://www.ruby-forum.com/t/calling-a-ruby-script-from-javascript/145742/3 "2008-08-13T15:57:36Z")

</div>

On 13 Aug 2008, at 14:28, Mark wrote:

> > > you  
> > > handler or something similar might be a better match. Be careful not  
> > > saying I should code it into the rails app? How would I go about  
> > > calling that via javascript?

If you’ve got it setup so that apache (or whatever) will execute your  
ruby script when you hit it at the right url then you don’t need to  
put it in the app.

If it were in your app then you’d just tell your javascript to hit  
proxy/?url=http://www.hovinne.com/feed/  
assuming your controller is called proxy and that the index action  
does the proxying,

Fred

---

<div class="post-metadata">

**Author:** ![mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@mark](https://www.ruby-forum.com/u/mark)\
**Post date:** [August 13, 2008, 3:29pm UTC](https://www.ruby-forum.com/t/calling-a-ruby-script-from-javascript/145742/4 "2008-08-13T15:29:25Z")

</div>

> > it and then using the result?  
> > Any help would be gratefully appreciated, I’m a bit stumped.
> 
> That should work fine. Just add an appropriate controller & action  
> that load the specified url for you  
> You might find that rails is a bit heavy-weight for that, a mongrel  
> handler or something similar might be a better match. Be careful not  
> to turn yourself into an open relay.
> 
> Fred

Sorry Fred I’m not sure what you mean, maybe I should explain a bit  
more about where I am: I’ve got a ruby script that will load the feed  
and output the xml code, and I want to have that returned xml parsed  
by jfeed.

At the moment this ruby script lives in my public folder, are you  
saying I should code it into the rails app? How would I go about  
calling that via javascript?

Thanks for your help.
