所以我看过以这种形式使用text_field和text_area的示例:
<%= form_for :account do |a| %>
Name: <%= a.text_field :name %><br />
Password: <%= a.text_area :password %><br />
Password Confirmation: <%= a.text_field :password_confirmation %><br />
<%= a.submit %>
<% end %>
我不明白其中的区别。 Rails初学者开发人员是否必须了解它们之间的区别?
我在API中发现了一些我不理解的解释-也许有人可以看一下,让我知道发生了什么。
对于“text_area”:
text_area(object_name, method, options = {})
Returns a textarea opening and closing tag set tailored for accessing a
specified attribute (identified by method) on an object assigned to the template
(identified by object).
Additional options on the input tag can be passed as a hash with options.
然后,对于“text_field”:
text_field(object_name, method, options = {}) Link
Returns an input tag of the “text” type tailored for accessing a specified
attribute (identified by method) on an object assigned to the template
(identified by object). Additional options on the input tag can be passed
as a hash with options. These options will be tagged onto the HTML as an
HTML element attribute as in the example shown.
最佳答案
a.text_field :name
解析为以下html<input type="text" name="name">
a.text_area :name
将解析为以下内容:
<textarea rows="4" cols="50">
</textarea>
取决于通过的选项。
最简单的查看方法是
text_field
为您提供单行文本的位置,其中text_area为多行文本提供一个区域。您可以将选项的哈希值传递给
text_area
帮助器,以指定行数和列数。在上面给出的示例中,将
text_field
或text_area
用作密码是不明智的做法,最好使用a.password_field
关于ruby-on-rails - form_for中text_field和text_area之间的区别,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20392374/