Creating interactive ajax javascript widgets in ruby ​​/ rails

Want to create an interactive javascript widget using ruby-on-rails, which can be placed on any website.

I can create a basic widget. Its pretty simple (like using document.write). This is great for receiving data from my server and entering it into the widget, but its most static.

But how do I create something more dynamic / interactive / ajaxy?

I want to be able to make ajax calls using link_to_remote or something else and be able to retrieve data from my server and update the widget when the user interacts with it.

Any ideas? If someone could point me in the right direction, that would be great.

Thanks!

+4
source share
2 answers

Since your goal is a widget that can be used from any website, you cannot use "Ajax" because of the "Security of the same origin" policy.

What you can do is create an interactive widget that uses the JSONP template to receive data from any server.

Using JSONP, your widget can interact with your site, even if it is part of some other web page that has nothing to do with your site.

There are libraries for using JSONP easily from your Javascript program. These include:

And others. In any case, you can use Rails as your backend.

+1
source

Instead of developing a new widget specification, I suggest looking at the W3C Widgets specification and implementing it in Ruby.

There is an existing Apache (Wookie) project that has some of its code already ported to Ruby. Wookie uses a server proxy to avoid the same release issues for Ajax widgets.

0
source

All Articles