ruby-on-rails – form_for中text_field和text_area之间的区别
发布时间:2020-12-17 02:46:33 所属栏目:百科 来源:网络整理
导读:所以我看到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.subm
所以我看到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,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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |