Increase vertical dimension simple form for - Text field

Viewed 110

I am creating a website where users can write their poetries. I created a simple form for where the user can write the title of the poetry, body of the poetry, and his name/nickname. Since the poetries are generally vertically long (short phrases with a lot of new lines), I am trying to expand vertically the dimension of the field: ':body'.

My simple form for is:

<br>
<div class="container">
  <div class="row ">
    <div class="col-sm-4 col-sm-offset-4">
      <%= form_for(poetry) do |f| %>
      <div class="form-group">
        <%= f.label :title, "Titolo"%>
        <%= f.text_field :title, as: :string, class: 'form-control'%>
      </div>

      <div class="form-group">
        <%= f.label :body, "Poesia"%>
        <%= f.text_field :body, as: :text, label: false, class: 'form-control' %>
      </div>

      <div class="form-group">
        <%= f.label :author, "Autore" %>
        <%= f.text_field :author, as: :string, label: false, class: 'form-control' %>
      </div>

      <%= f.submit "Conferma",  class:"btn btn-secondary btn-lg" %>
      <% end %>
    </div>
  </div>
</div>

I tried to add the following pieces of code, but they are not working.

:input_html => {:maxlength => 15, :size => 40}

:input_html => {:maxlength =>2,:style=> 'width: 20px'}

<%= f.text_field, :input_html => {:rows => 10} %>
1 Answers

You do not need to scope the size attribute under :input_html. Rails documentation for text_field has some examples, and text_field_tag shows the defined options available.

<%= f.text_area :title, rows: 40 %>

Conversely, if you are meaning to use simple_form you need to use simple_form_for instead of form_for.

<%= f.text_field :message, input_html: {rows: 10} %>

Related