K
K
Konstantin Alikhanov2016-02-16 13:38:50
Ruby on Rails
Konstantin Alikhanov, 2016-02-16 13:38:50

Where do extra spaces come from before lines when rendering a multiline string in a textarea?

Good afternoon, I took Rails5 for a new project and immediately stumbled upon a problem.
In short, there is a model with a text string field that needs to be edited in the textbox. Form code:

.form
  =form_for article do |f|
    .form-group
      =field_label f, :text, true
      =f.text_area :text, class: %w(form-control), rows: 20, placeholder: t('placeholder.article_text')

On Create, everything is saved normally, but on Edit, several spaces appear before each new line in the textbox.
Empirically reduced the exploit to the simplest. Even a simple test.html.erb file:
<textarea><%= "a\nb\nc" %></textarea>
It looks like this on the page:
Z09F4.png
Even a simple <p><%= "a\nb\nc" %></p>one also pushes a bunch of spaces, just the browser trims them (visible in the developer console)
What to do and how to deal with it? Is this a bug (feature) of the fifth rail or what?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question