Re: Display a string properly in View

Gavin
Thu, 18 Jun 2009 09:25:19 -0000

Hi Valentino

You shouldn''t use puts, for output in the view.

You probably want to split the info for each event into seperate cells
so your table is well-structured.
In which case I''d write a helper_method and throw most of the work
into there.

If not, you can stop html from collapsing white-space by either
replacing each space with &nbsp; (non-breaking space) or set the
table''s style:

table {
  white-space: pre;
}

in your css.

Gav

http://handyrailstips.com

On Jun 18, 10:12 am, Valentino Lun
<rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:
> Dear all
>
> I have problem in print the string in View.
>
> @event = Event.first
>
> puts @event.event_detail
> dreq_reqno   dreq_status  dreq_create_time
> 09P0917228   0            18 Jun 2009 16:32
> 09P5075748   0            18 Jun 2009 16:32
> 09P5075755   0            18 Jun 2009 16:33
> The format is pretty good using puts
>
> But when I print this in View, the format disorder (Some spaces are
> trimmed.)..
> <%= @event.event_detail.event_detail.gsub("\n",
" ") %>
> dreq_reqno dreq_status dreq_create_time
> 09P0917228 0 18 Jun 2009 16:32
> 09P5075748 0 18 Jun 2009 16:32
> 09P5075755 0 18 Jun 2009 16:33
>
> How can I have the "puts @event.event_detail" in View?? I tried
this,
> but not work.
> <%= puts @event.event_detail %>
>
> Many thanks
> Valentino
> --
> Posted viahttp://www.ruby-forum.com/.