Showing only one space instead of more than one spaces in Rails
I am facing a problem of the spacing in a table values.
I have a simple table with a header Item Title
and I am showing its value in it,
but for the value 'Salil Gaikwad' it is just showing Salil Gaikwad
.
It means it is simply showing one space for more than one spaces when I retrieve
it as <%= @item.item_title %>
but I want to show it the sam开发者_运维百科e way as it is saved in the database
i.e. Salil + 5 spaces + Gaikwad
You could use the html tag pre around your text in the cell to preserve the spaces. Otherwise you can substitute the spaces with the html char   with something like this:
@item.item_title.gsub(/\s/, " ")
It's an html thing.
Try to wrap the result in pre tags (
<%= ... %>)
Or you can use the css white-space: property, using the needed selector.
Easiest solution is to use the css white-space property on your html table. Since you want to preserve the white space, you can use the pre, pre-wrap, pre-line values as need.
See this link for reference: http://www.w3schools.com/cssref/pr_text_white-space.asp
table { white-space: <one of pre, pre-wrap, pre-line>; }
精彩评论