dig*_*tie 9 css ruby-on-rails actionview helpers ruby-on-rails-3
我正在尝试将一个类应用于Rails 3中button_to生成的表单.
该:class
选项设置提交按钮的类,以便文档告诉我们:form_class
将类应用于表单.
例如
<%= button_to 'x', user_contact_path(@user, contact), :method => :delete, :form_class => "delete" %>
Run Code Online (Sandbox Code Playgroud)
这只是将属性添加form_class="delete"
到按钮元素.我尝试过使用各种组合:html_options
等等.
有人知道怎么做吗?
Sye*_*lam 15
这种方法对我来说非常好.我能做到:
<%= button_to "Hello", root_url, :method => :get, :form_class => "my_class" %>
Run Code Online (Sandbox Code Playgroud)
以上产生以下内容:
<form action="http://localhost:3000/" class="my_class" method="get">
<div><input type="submit" value="Hello"></div>
</form>
Run Code Online (Sandbox Code Playgroud)
但是,这在Rails 3.1中作为问题点中的链接,并且由于表单类是硬编码的,因此在Rails 3.0.x中也不起作用.
来自url_helper代码:
("<form method=\"#{form_method}\" action=\"#{html_escape(url)}\"
#{"data-remote=\"true\"" if remote} class=\"button_to\"><div>" +
method_tag + tag("input", html_options) + request_token_tag +
"</div></form>"
).html_safe
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
15169 次 |
最近记录: |