# Calling a ruby script from javascript

**URL:** <https://discuss.rubyonrails.org/t/calling-a-ruby-script-from-javascript/33143>\
**Category:** rubyonrails-talk\
**Created:** [August 13, 2008, 1:13pm UTC](https://discuss.rubyonrails.org/t/calling-a-ruby-script-from-javascript/33143 "2008-08-13T13:13:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark10](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@Mark10](https://discuss.rubyonrails.org/u/Mark10)\
**Post date:** [August 13, 2008, 1:13pm UTC](https://discuss.rubyonrails.org/t/calling-a-ruby-script-from-javascript/33143/1 "2008-08-13T13:13:01Z")

</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:// 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:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [August 13, 2008, 1:17pm UTC](https://discuss.rubyonrails.org/t/calling-a-ruby-script-from-javascript/33143/2 "2008-08-13T13:17:10Z")

</div>

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:** ![Mark10](https://avatars.discourse-cdn.com/v4/letter/m/df705f/32.png) [@Mark10](https://discuss.rubyonrails.org/u/Mark10)\
**Post date:** [August 13, 2008, 1:28pm UTC](https://discuss.rubyonrails.org/t/calling-a-ruby-script-from-javascript/33143/3 "2008-08-13T13:28:17Z")

</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:// \>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.
> 
> 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.

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [August 13, 2008, 1:56pm UTC](https://discuss.rubyonrails.org/t/calling-a-ruby-script-from-javascript/33143/4 "2008-08-13T13:56:30Z")

</div>

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=[jfhovinne](http://www.hovinne.com/feed/) assuming your controller is called proxy and that the index action does the proxying,

Fred
