eomeroff
eomeroff

Reputation: 9915

Rails more then one empty space

I want to retrieve string from database with rails (Rails 2.3.8 andy jruby 1.6.5.1) that looks like "I am human", but in a browser it always looks like "I am human". There is no extra spaces in between. How can I keep extra spaces, or what is striping the string.

Operation is pretty simple, just pull a string and show it in view.

Thanks.

Upvotes: 1

Views: 907

Answers (2)

Amadan
Amadan

Reputation: 198314

Nothing is stripping the string - it's the semantics of HTML that is screwing you over. All consecutive spaces in HTML are rendered as a single space, unless explicitly prevented by a <pre> element, or equivalent CSS rule (white-space). You can also keep your spaces if you convert them to another kind of space - a non-breaking space (&nbsp;) does not get collapsed.

Upvotes: 3

Pavel S
Pavel S

Reputation: 1543

browsers interpret usual spaces this way. One can use &nbsp; to keep spaces. do

string_from_db.gsub(' ', '&nbsp;')

or use <pre> tag.

Upvotes: 1

Related Questions