String in rails and ruby show first n character

I am just wondering how can i show the first 200 character of a string ?
with rails. My application his has follow

<%= f.description %>
I have try the follow

<%= f.description(200).to_s %>
But it doesn't work. Thanks in advance and description is a text area

···

--
Posted via http://www.ruby-forum.com/.

Use String#[]: http://www.ruby-doc.org/core-1.9.3/String.html#method-i-5B-5D

<%= f.description[0, 200] %>

-- Matma Rex

In Rails, you can also utilize the truncate helper method:

<%= truncate(f.description, :length => 200, :separator => ' ') %>

This will ensure the string is not chopped off in the middle of a word.

···

On 08/29/2012 08:34 PM, Bartosz Dziewoński wrote:

Use String#: Class: String (Ruby 1.9.3)

<%= f.description[0, 200] %>

--
Lars Haugseth

Lars Haugseth wrote in post #1073861:

···

On 08/29/2012 08:34 PM, Bartosz Dziewoński wrote:

Use String#: http://www.ruby-doc.org/core-1.9.3/String.html#method-i-5B-5D

<%= f.description[0, 200] %>

In Rails, you can also utilize the truncate helper method:

<%= truncate(f.description, :length => 200, :separator => ' ') %>

This will ensure the string is not chopped off in the middle of a word.

Thanks both works, didn't know about both of them

--
Posted via http://www.ruby-forum.com/\.