Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在rails中,我见过类似的代码
form_for(@post, html: {:class => "foo"})
但有时rails自动将它无法识别的任何键转换为html?
在上面的例子中,如果你不使用:html键,类分配将不会反映在 DOM 中。
:html
什么时候用这个?
根据文档,只要您想向表单标签添加属性,就应该使用 html 选项:
":html - 表单标签的可选 HTML 属性。"
rails 可以选择其他预定义的选项。有很多。您可以在文档中准确查看哪个。
只是因为 rails form_for 是这样定义的……您始终可以在传递正确的选项及其顺序时检查 api。
http://api.rubyonrails.org#for_for