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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> > 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) "<p>" << h(text).gsub(/\n/,"</p><p>") << "</p>" end in view: <%=format_text(@picture.result)%> -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Luke Pearce <rails-mailing-list@...> writes:> Perhaps make a helper and do the following: > > in application helper: > def format_text(text) > "<p>" << h(text).gsub(/\n/,"</p><p>") << "</p>" > end > > in view: > > <%=format_text( <at> picture.result)%> >There''s already a helper in Rails to do this... <%= simple_format @picture.result %> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Darren Evans 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 -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---