# Hi, how can I split line length in Rails?

**URL:** <https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102>\
**Category:** Rails\
**Created:** [May 24, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102 "2010-05-24T15:55:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ainar\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Ainar\_A](https://www.ruby-forum.com/u/Ainar_A)\
**Post date:** [May 24, 2010, 3:55pm UTC](https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102/1 "2010-05-24T15:55:54Z")

</div>

Hi to everyone! I need to split one long line in two or multiple  
lines… how can I do that? I have a form where you can write in for  
example 200 character long line (“aaaaaaaaa…”), when I submit  
it(line contains no spaces), char line updates in my blog, but the  
only bug is there that line is posted in its real length 200 chars  
from left to right all over other borders, can I set maxlength of it  
or something like that? (Example: when form echoes line it should be  
100px long height:relative)

---

<div class="post-metadata">

**Author:** ![Ainar\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Ainar\_A](https://www.ruby-forum.com/u/Ainar_A)\
**Post date:** [May 24, 2010, 5:53pm UTC](https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102/2 "2010-05-24T17:53:16Z")

</div>

Ainar A. wrote:

> Hi to everyone! I need to split one long line in two or multiple  
> lines… how can I do that? I have a form where you can write in for  
> example 200 character long line (“aaaaaaaaa…”), when I submit  
> it(line contains no spaces), char line updates in my blog, but the  
> only bug is there that line is posted in its real length 200 chars  
> from left to right all over other borders, can I set maxlength of it  
> or something like that? (Example: when form echoes line it should be  
> 100px long height:relative)

Just split words that are more than a certain number of characters long.  
Ruby’s String and Regexp classes have many methods that will help you.

For further help, I’d recommend that you go to the Ruby list, as this is  
basically not a Rails question.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Ainar\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Ainar\_A](https://www.ruby-forum.com/u/Ainar_A)\
**Post date:** [May 24, 2010, 6:19pm UTC](https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102/3 "2010-05-24T18:19:20Z")

</div>

use text\_area  
for example  
\<%=  
text\_area(:product,:description ,:size=\>“100x10”,:disabled=\>“disabled”)  
%\>

I hope that will help.

On May 24, 3:13 pm, Ainar A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Ainar\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Ainar\_A](https://www.ruby-forum.com/u/Ainar_A)\
**Post date:** [May 25, 2010, 12:18am UTC](https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102/4 "2010-05-25T00:18:05Z")

</div>

axelsef wrote:

> use text\_area  
> for example  
> \<%=  
> text\_area(:product,:description ,:size=\>“100x10”,:disabled=\>“disabled”)  
> %\>
> 
> I hope that will help.
> 
> On May 24, 3:13ï¿½pm, Ainar A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

That’s a really bad solution. Disabled objects are usually a  
sign that you’re doing something wrong.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![Ainar\_A](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/f6c823/32.png) [@Ainar\_A](https://www.ruby-forum.com/u/Ainar_A)\
**Post date:** [June 10, 2010, 11:46am UTC](https://www.ruby-forum.com/t/hi-how-can-i-split-line-length-in-rails/189102/5 "2010-06-10T11:46:53Z")

</div>

However thank you all,  
I found solution, I write few lines in posts helper and everything  
works fine  
module PostsHelper  
def wrap(content)  
content.split.map{ |s| wrap\_long\_string(s) }.join(’ ')  
end

private

```
def wrap_long_string(text, max_width = 30)
  zero_width_space = "&#8203;"
  regex = /.{1,#{max_width}}/
  (text.length < max_width) ? text :

```

text.scan(regex).join(zero\_width\_space)  
end

end
