my blog is abt wht i have learnt technically, mostly in Ruby on Rails, Javascript, node.js
hope this share a little bit of info & adds a bit stuff.,
Thanks.
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..."
In Rails 3.0 you have a helper strip_tags. Example: you have a product and you want to show the description you do it in a line of code <%= truncate(strip_tags(product.description), :length => 80) %>
By the way you can use SyntaxHighlighter to make the code from your blogspot pretty. http://alexgorbatchev.com/SyntaxHighlighter/
2 comments:
In Rails 3.0 you have a helper strip_tags. Example: you have a product and you want to show the description you do it in a line of code
<%= truncate(strip_tags(product.description), :length => 80) %>
By the way you can use SyntaxHighlighter to make the code from your blogspot pretty. http://alexgorbatchev.com/SyntaxHighlighter/
Thanks, i tried many options but this finally worked.
<%= truncate(strip_tags(product.description), :length => 80) %>
Post a Comment