I just upgraded to Snow Leopard and went to edit some code on a legacy Rails app (1.2.5) and found that the views cause a crash when trying to render the 'truncate' text helper. I took them out and it rendered fine. How do you fix this? Are there other methods that might see the same issue?
views:
103answers:
1
+1
A:
I found this bit of code which seems to be the fix, however I'm wondering if there is a less hackish way to do it.
# place the following code at the end of your config/environment.rb
module ActionView
module Helpers
module TextHelper
def truncate(text, length = 30, truncate_string = "...")
if text.nil? then return end
l = length - truncate_string.chars.to_a.size
(text.chars.to_a.size > length ? text.chars.to_a[0...l].join + truncate_string : text).to_s
end
end
end
end
bwizzy
2009-10-05 02:23:44
I think this is probably the best way to do it. Rails versions less than 2.2 are not compatible with Ruby 1.8.7.
Peter Wagenet
2009-10-05 18:28:04