顯示具有 massage 標籤的文章。 顯示所有文章
顯示具有 massage 標籤的文章。 顯示所有文章

2007/7/28

massage: A SPA plugin for Rails

SPA Stands for Single Page Application, it's a concept that totally depends on AJAX. We just made an Rails controller extension that makes it so easy to do spa, it's called: massage. (We are really enjoying it when the name feels just right, aren't we.)

The massage project is now on Rubyforge. To try it, first you would need to install it as a Rails plugin like this:

script/plugin install http://massage.rubyforge.org/svn/trunk/

Then, in the controller that you want to make it work like SPA, add:

spa :only => [:index, :settings]    # or :except => [...]

This would make index and settings actions work just right for both xhr and non-xhr. Non-XHR would show the page just like it was, and it'll work if you change those calls to link_to to link_to_remote too. By default, it uses RJS to update an element with id "content" (better to be a div for best look). If you need to change it to, say, "my-spa-arena", you can say:

spa :only => [:index, :settings], :update_element => "my-spa-arena"

And of course, make sure there's is such an element inside your layout, otherwise RJS would just pop-up an error message.

massage project is still at bleeding edge, if you find it broken please contact us, you can leave comments here.