Rails text_area size

Ruby on-Rails

Ruby on-Rails Problem Overview


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.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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" %>

Solution 2 - Ruby on-Rails

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

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

Solution 3 - Ruby on-Rails

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwhirlwinView Question on Stackoverflow
Solution 1 - Ruby on-RailsDanneManneView Answer on Stackoverflow
Solution 2 - Ruby on-RailsfatfrogView Answer on Stackoverflow
Solution 3 - Ruby on-RailsssriView Answer on Stackoverflow