gpt4 book ai didi

ruby-on-rails - 将类添加到生成的表单的正确 button_to 语法是什么?

转载 作者:技术小花猫 更新时间:2023-10-29 10:55:45 25 4
gpt4 key购买 nike

我正在尝试将一个类应用到 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 等尝试了各种组合。

有人知道怎么做吗?

最佳答案

这种方法对我来说非常有效。我能够做到:

<%= button_to "Hello", root_url, :method => :get, :form_class => "my_class" %>

以上生成以下内容:

<form action="http://localhost:3000/" class="my_class" method="get">
<div><input type="submit" value="Hello"></div>
</form>

但是,这是在 Rails 3.1 中作为您问题点中的链接,并且自 form class is hard coded 以来在 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

关于ruby-on-rails - 将类添加到生成的表单的正确 button_to 语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9295929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com