views:

49

answers:

2

Looking to create interactive javascript widget using ruby-on-rails that can be placed on any website.

I am able to create a basic widget. Its fairly straightforward (eg. using document.write) This works fine for taking data from my server and putting it into the widget but its very static.

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

I want to be able to do ajax calls using link_to_remote or something and be able to pull data from my server and update the widget as a user interacts with it.

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

Thanks!

A: 

Since your goal is a widget that can be used from any website, you can't use "Ajax" due to the Same origin security policy.

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

Using JSONP, your widget can interact with your website even though it is a part of some other webpage that has nothing to do with your website.

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

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

Larry K
A: 

I suggest rather than develop a new widget spec, that you take a look at the W3C Widgets specification and implement that in Ruby.

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

scottw