TradeRaider
TradeRaider

Reputation: 754

Html strips out white spaces.

This is a bit silly. I use Rails for my web app. It acquires data from the database using statements like

<div class="show-content"> <%= @page.content %> </div>

A sample html output of the same.

<div class="show-content">
Migrations are a convenient way for you to alter your database in a structured and organized manner.

Active Record tracks which migrations have already been run so all you have to do is update your source and run rake db:migrate. 

Migrations also allow you to describe these transformations using Ruby. 
</div>

As you can see, they consist of 3 paragraphs. But when they get displayed, the newlines(whitespaces) get stripped, which is not what I want. Should I create a helper or is there an inbuilt function to do that?

Upvotes: 0

Views: 752

Answers (2)

dKen
dKen

Reputation: 3127

Try using simple_format() which transforms the input using HTML rules. TextHelper#simple_format documentation

Upvotes: 5

Mike Corcoran
Mike Corcoran

Reputation: 14565

you are going to probably have to do one of two things.

process the content on the server so each 'line' gets wrapped in <p> tags and style them as needed

or

change your template to something like this:

<div class='show-content'>
    <pre><%= @page.content %></pre>
</div>

Upvotes: 1

Related Questions