Ruby on Rails Blog Live Ajax Comments Previewing

It seemed strange to me that there was no default asynchronous comments on this web spiffy blog and I was never a huge fan of preview buttons myself so I hacked in a live preview! Go ahead and give it a whirl. This very simple code can be used for far more then the blog app typo that runs this site. It can observe any form you have on your sites or projects.

To implement it an your own blog, edit app/views/articles/_comment_box.rhtml and do the following:

# below <%= end_form_tag %> put: 

  <%= observe_form "commentform", 
        :frequency => 2, 
        :update => "preview",
        :complete => "Element.show('preview')",
        :url => { :action => "comment_preview" } %>

I did leave the preview button there but eventually it may depreciate.