Whitespace added while editing record

Hello there and happy holidays.

I’m not sure if the surprise for what I’m seeing in my forms is
justified, but I am very surprised, so here’s the thing.

  • I have a simple model with a single text field named ‘content’.

  • I run the app and create a new record.

  • I write “one two three four” into the ‘content’ textarea and save the
    record. The text is properly displayed by the “show” action.

  • Now I edit the same record (or create a new one, it doesn’t matter),
    this time entering

one
two
three
four

i.e. newline-separated strings. As expected, the saved record is
displayed inline as the previous one, if no extra processing (such as
textile or markdown) is done on the output.

  • Now, edit the record, look at the textarea field, and here’s the weird
    thing (to me at least)

one
two
three
four

I’m hoping that the post will retain the layout of what I’ve just typed,
i.e. the text passed to the textarea through the model’s instance
variable is split into four lines, with A BUNCH OF WHITESPACE BEFORE
EACH LINE, except for the first.

If I update the record without touching the textarea, this whitespace
will be saved as well. Editing and updating again and again the record
results in the three lines being moved further and further off to the
right, with the size of the record growing accordingly, as shown through
the console.

Am I missing something quite obvious?
So sorry to have bothered you all if I am.

Cheers and thanks in advance,
Giuseppe

On Dec 29, 2007, at 12:14 PM, Giuseppe B. wrote:

Hello there and happy holidays.

I’m not sure if the surprise for what I’m seeing in my forms is
justified, but I am very surprised, so here’s the thing.

Am I missing something quite obvious?
So sorry to have bothered you all if I am.

Cheers and thanks in advance,
Giuseppe

Will you please post the form code?

Peace,
Phillip

Will you please post the form code?

Phillip,

thanks for your response, it worked like a charm!
Seriously, it got me thinking a little harder, like I should have in the
first place, and I found out what the problem was.

I am using HAML to produce views instead of ERb. I like it a lot because
of its cleaniness, in terms of both source and output, but it does have
a problem with

, , and  output, as detailed here:

http://www.mail-archive.com/[email protected]/msg01593.html

The code for my form was:

#note
%h1 Editing note
= error_messages_for :note
- form_for(@note) do |f|
= f.text_field :title
= f.text_area :content
= submit_tag “Save”
= link_to “Cancel”, notes_path

It seems to work properly after the following change:

  ~ f.text_area :content

Thanks again and peace to you,
Giuseppe

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