Rails text_area size

我有一个 text_area在一个 fields_for里面,它在一个 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.

73377 次浏览

你可以选择:

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

或者可以使用 size 属性同时指定:

<%= day_form.text_area :hatch, size: "30x10" %>

由于文本区域同时具有行和列,因此必须同时指定行和列

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

对于文本字段可以使用

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

Http://api.rubyonrails.org/classes/actionview/helpers/formhelper.html#method-i-text_area

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

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