Sunday, October 24, 2010

HTML stripping, Truncating string in Ruby, Rails

For Truncating String I have used 'truncate' rails helper method.
limiting to 10 characters
truncate("im srikanth glad to meet you", 10)
>> "im srik..."
For HTML stripping, I have used gsub..
str.gsub(/<\/?[^>]*>/, "")

Sunday, October 3, 2010

Weekday or not..

You can Use this ,

def weekday?
(1..5).include?(wday)
end

check ..

d = Date.today
=> Mon, 04 Oct 2010
d.weekday?
=> true
d = Date.today - 1
=> Sun, 03 Oct 2010
d.weekday?
=> false