Ruby-on-rails Rails 表单文本字段助手,如何使输入区域更宽?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4457446/
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
Rails form text field helper, how to make the input area wider?
提问by Blankman
How do I make the text field area wider?
如何使文本字段区域更宽?
I tried:
我试过:
f.text_field :title, size => 150
f.text_field :title, size => 150
I also tried width, I am missing something here, what is it?
我也试过宽度,我在这里遗漏了一些东西,它是什么?
回答by Jimmy Huang
I think it should be
我认为应该是
f.text_field :title, :size => 150
Or, you can add :class option and use css to define the size (I prefer)
或者,您可以添加 :class 选项并使用 css 来定义大小(我更喜欢)
回答by Mark Locklear
You can also do something like:
您还可以执行以下操作:
<%= f.text_area :description, :cols => "10", :rows => "10" %>
回答by ssri
Are you using the same in your code. I think you are missing a colon before the size.
您是否在代码中使用相同的内容。我认为您在大小之前缺少一个冒号。
<%= f.text_field :title, :size => 150 %>
<%= f.text_field :title, :size => 150 %>
or you can use
或者你可以使用
<%= f.text_field :title, "size" => 150 %>
<%= f.text_field :title, "size" => 150 %>
size is an undefined local variablewhereas :size and "size"are passed as options to the text field form helper
size 是一个未定义的局部变量,而:size 和 "size"作为选项传递给文本字段表单助手
回答by Jyothu
You can do it by simply using rows optionin your text field. Like
您只需在文本字段中使用行选项即可。喜欢
<%= f.text_area :fieldname, :rows => "10" %>
回答by user2563022
Try this for the input field
试试这个输入字段
<%= f.input :content, as: :text, input_html: { rows: "2" } %>
回答by mbreedlove
回答by Aditya Manohar
You can always specify a class using the class symbol and specify a width using CSS
您始终可以使用类符号指定类并使用 CSS 指定宽度
<%=text_field_tag 'some_input', nil, :class => 'some-class'%>
<%=text_field_tag 'some_input', nil, :class => 'some-class'%>

