KRJS: RJS without messing the Views
Posted by choonkeat Sun, 11 Jun 2006 20:02:00 GMT
RJS is great and awesome. I use it quite regularly now. With RJS, I don't have to deal with which parts of the page to update in the rhtml files - I get to decide whilst in my controller using the nice and elegant render :update. Sweet.
But part of me wished I didn't have to even decide which page elements are to be ajaxified. I'd wish I could more easily enable a link, form or button to make ajax calls without going back and touching my html...
Oh well.
Introducing the KRJS plugin, with less than 60 lines of patch to Rails' ActionPack itself (which probably means bugs are aplenty, would slow production sites to a crawl, and that its fresh from the oven too)
To see KRJS in action (so what does it do?), generate a blank controller and index action:
./script/generate controller Sample index
Give it a decent layout (include javascripts) by creating the file app/views/layouts/sample.rhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%= javascript_include_tag :defaults %>
<%= @content_for_layout %>