Ruby-on-rails Rails 文本区域大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4223931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 23:39:40  来源:igfitidea点击:

Rails text_area size

ruby-on-rails

提问by whirlwin

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

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

可以改变大小text_area吗?例如:day_form.text_area size: 5

回答by DanneManne

You could either go with:

你可以选择:

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

or you can specify both with the size attribute:

或者您可以使用 size 属性指定两者:

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

回答by fatfrog

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

为了响应性,我喜欢使文本区域宽度为 100% :

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

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

回答by ssri

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

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