82

I have a text_area inside a fields_for, which is inside a form_for.

<%= day_form.text_area :hatch %>

Is it possible to change the size of the text_area? For example: day_form.text_area size: 5.

3 Answers 3

160

You could either go with:

<%= day_form.text_area :hatch, cols: 30, rows: 10 %>

or you can specify both with the size attribute:

<%= day_form.text_area :hatch, size: "30x10" %>
3
  • 4
    this does not work now is there a rails 3.1 solution which is different from this one?
    – Dev R
    Commented May 11, 2012 at 10:23
  • I didn't see this mentioned, but you can also write it like so: <%= f.text_area :text, :size => "60%x5%" %> This is in Rails 4.0.0
    – kyle
    Commented Aug 23, 2013 at 3:13
  • I had to change f.text_field to f.text_area.
    – flobacca
    Commented Oct 10, 2013 at 0:33
12

For responsiveness I like to make the text area width 100% :

<%= f.text_area :description, rows: 10, style: 'width:100%;' %>

3

As text area has both row and column you have to specify both

<%= text_area(:application, :notes, cols: 40, rows: 15, class: 'myclass') %>

For text field can use

<%= text_field(:application, :name, size: 20) %>

http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-text_area

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.