将类添加到生成的表单的正确的 button_to 语法是什么?
我正在尝试将一个类应用于Rails 3中button_to生成的表单。
:class
选项设置提交按钮的类,因此 docs 告诉我们使用 :form_class
将类应用于表单。
例如,
<%= button_to 'x', user_contact_path(@user, contact), :method => :delete, :form_class => "delete" %>
这只是将属性 form_class="delete"
添加到按钮元素。我尝试了使用 :html_options
等的各种组合。
有人知道该怎么做吗?
I'm trying to apply a class to the form generated by button_to in Rails 3.
The :class
option sets the class for the submit button so the docs tell us to use :form_class
to apply a class to the form.
E.g.
<%= button_to 'x', user_contact_path(@user, contact), :method => :delete, :form_class => "delete" %>
This just adds the attribute form_class="delete"
to the button element. I've tried various combinations using :html_options
and so on.
Anybody know how to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个方法对我来说非常有效。我能够做到:
上面生成以下内容:
但是,这是在 Rails 3.1 中作为您的问题点中的链接,并且同样的内容在 Rails 3.0.x 中不起作用,因为 表单类是硬编码的。
来自 url_helper 代码:
That method works perfectly fine for me. I am able to do:
the above generates the following:
However, this is in Rails 3.1 as the link in your question points and the same wouldn't work in Rails 3.0.x since the form class is hard coded.
From url_helper code:
尝试使用
此强制
:form_class => “delete”
成为options
哈希的一部分,而不是html_options
哈希。Try with
This forces
:form_class => "delete"
to be part of theoptions
hash instead of thehtml_options
hash.