Truncating HTML in Ruby

Update: You should read the comments, then check out the extended verion of truncate_html that uses Tidy. For the blogging Web site we wanted snippets of blog post for the front page and search results. This wasn’t a problem at all for our test blog posts, which we made by pasting lorem ipsum into a […]

STI, acts_as_tree, and xml_response_from

More Land Brokr/NCRE integration means more xml_response_fromhackery. This one involves the message center. NCRE messages are STI trees. That is: class Message < ActiveRecord::Base acts_as_tree :order => ‘created_at DESC’ end class PurchaseMessage < Message def summary “blah blah” end end class OpenHouseMessage < Message def summary “blah blah” end end So the code to send […]

STI and to_xml

As I mentioned in the explanation for my response_from plugin, I have two apps that communicate via a private XML REST API. This is trivial using my xml_response_from method (in my response_from plugin) and with Rail's to_xml; trivial, that is, unless you want to use single table inheritance. For example, let's say you have:  class […]

response_from: the opposite of respond_to render :xml

Update: This can be replaced, mostly, with Rails 2.0’s ActiveRecord#from_xml. As I assured in a prior post, I spent today hacking on a plugin to make it easier to consume XML REST APIs. The result is the ResponseFrom plugin. It's the opposite of this:  respond_to { |w| w.xml { render :xml => User.find_first } } […]

REST Hacking

First off, many thank yous to Brian Del Vecchio for linking to MyNCRE from BostonWTF. It's an awesome idea and Brian's an awesome guy. Thanks!  In other news, I spent much of today hacking on a REST XML API. The good news: respond_to is awesome, as is render's :xml argument and especially ActiveRecord::Base's to_xml method. […]