Insert all the helpers you want and “go!”.strip_tags.auto_link.truncate(25)
# ActionView text helpers
# http://grosser.it/2009/05/30/all-actionview-helpers-on-strings/
class String
%w[auto_link excerpt highlight sanitize simple_format strip_tags word_wrap].each do |method|
define_method method do |*args|
ActionController::Base.helpers.send method, self, *args
end
end
# called with a number or with :length=>10
def truncate(*args)
if args.first.is_a?(Hash)
ActionController::Base.helpers.truncate(self, *args)
else
ActionController::Base.helpers.truncate(self, :length=>args[0])
end
end
end

2 comments
Comments feed for this article
2009-05-31 at 14:10:08
Daily Digest for May 31st | Michael Bumann
[...] All ActionView Helpers on Strings — 8:22am via Google [...]
2010-06-12 at 5:58:21
MySql: 4 ways to lower the impact of TEXT columns « My Pragmatic life — Michael Grosser
[...] needs truncate on string) And e.g. in the UI the text could always show truncated to 255 chars and only on click it is [...]