Carriage return retrievel using RoR

Hi

If I have for example:

Test 1

Test 2

in the field result in the picture table in my database, then using
@picture.result I get:

Test 1 Test 2

i.e. the carriage return is missing. Does anyone know an easy way to
overcome this so that my preview is correct?

Many thanks

Darren

i.e. the carriage return is missing. Does anyone know an easy way to
overcome this so that my preview is correct?

Perhaps make a helper and do the following:

in application helper:
def format_text(text)

” << h(text).gsub(/\n/,"

") << “


end

in view:

<%=format_text(@picture.result)%>

Luke P. <[email protected]…> writes:

There’s already a helper in Rails to do this…

<%= simple_format @picture.result %>

Darren E. wrote:

i.e. the carriage return is missing. Does anyone know an easy way to
overcome this so that my preview is correct?

No need to create a special helper. Rails already has one!

In your view:

<%= simple_format @picture.result %>

See
http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000513

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs