The Accelerate HR Blog

Truncating with dignity in Rails   (Sun Dec 02 2007)

I noticed that my RSS feed was showing you post titles but no content. Which would be fine if I wanted to drag you kicking and screaming into my site. But I'd prefer you to come along quietly, if you don't mind sir / mad ...

So I needed to find out how proper programmers did it. Well that wasn't too hard: I'd just missed a line in my xml.

Now, as you've seen, I'm not someone who writes twenty words when a thousand would do. But for the feed content, I thought a little truncating would be in order, just giving you enough detail to tempt you in. And that's when I came across a little gem (no, gem, not Gem) from Daniel Morrison, posted a few months back - awesome_truncate. What does it do? Unlike the normal Rails truncate, it doesn't hack off your flow in mid-word - like some paragraphs not too distant from here. It's just a little 5-line method with a nice little regular expression for those of you who are into that. You could use it as a helper, or tie it directly into your model, as I did. Nice touch, Daniel - thank you.

Now I wonder if the feed's still going to work?


1 hour later: Nope. It didn't. So you've still got no content in the feed. But it's not our little truncate helper causing the problem. Thats working fine - as you'll see if you go do a blog-search. But for some reason, the line I added to the xml just doesn't want to work, whether the content is truncated or not. Back to the drawing board.


Much later: Think we've got a problemette with valid xml - and that means tests. There'll be more about this.

Filed under: Ruby on Rails




Comment 10 months ago from Daniel Morrison

Glad you found the code useful. Cheers!


List recent Entries
List all blog entries filed under:

Employment Politics
HR
Implementation
Just thoughts
Ruby on Rails
Web 2.0

Can't find what you're looking for? Try this: -

Search blog for a word or phrase



 Subscribe to an RSS feed

Or get an email copy every time we post something new. Nothing new? Nothing mailed

Enter your email address:

Delivered by FeedBurner


If you're enjoying our blog, why not find out more, and maybe get involved?

ACCELERATE HR is a website built on Rails and designed for the enterprise. And we're building it live on the Web, right here.

Check out our home page HERE, or sign up for free HERE.


DESERT ISLAND BLOGS

Sharing a few of my favorites

HR Stimuli
McArthur's Rant

Jon Ingham's Strategic Human Capital Management Blog

The Rails Track
Railscasts

Web Power
The Technology Edge

Window on the Gulf
Mahmood's Den