Reputation: 8257
I have a very simple Rails form.:
= form_for @object :remote => true do |form|
= form.text_area :text, :class => 'form-control'
For a new object, with a nil text attribute, this generates:
<textarea class="form-control" name="object[text]" id="object_text"> </textarea>
The blank space in that is a newline:
(byebug) form.text_area :text, :class => 'form-control'
"<textarea class=\"form-control\" name=\"user_deactivation[reason_text]\" id=\"user_deactivation_reason_text\">\n</textarea>"
I strip out the leading and trailing spaces on save, so data wise, its not a big deal, but when the user clicks on this field, it appears indented.
Relevant software versions:
Why is this newline being generated and how can I stop it?
Upvotes: 1
Views: 310
Reputation: 4434
You can use the '~' operator, which is like the '=' operator, but automatically runs find_and_preserve on the output.
Like this:
= form_for @object :remote => true do |form|
~ form.text_area :text, :class => 'form-control'
Upvotes: 2
Reputation: 8257
This is not an ideal answer, but it does work. I would like something better:
= find_and_preserve(form.text_area :text, :class => 'form-control')
Can that be automatic? Is there a way to have the text_area helper not insert a newline?
Upvotes: 0