Reputation: 9915
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
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 (
) does not get collapsed.
Upvotes: 3
Reputation: 1543
browsers interpret usual spaces this way. One can use
to keep spaces.
do
string_from_db.gsub(' ', ' ')
or use <pre>
tag.
Upvotes: 1