这是为什么button_to渲染不正确Rails中3.2.11?这是、不正确、button_to、Rails

2023-09-10 20:52:33 作者:单身、不需要解释

我在工作中的Rails 3.2.11,我想不通为什么这个按钮将不会按照API文档呈现。具体来说,我无法获得数据的远程属性来正确地呈现。是否有一个错误,在我的code?

I am working in Rails 3.2.11 and I cannot figure out why this button will not render per the API documentation. Specifically, I cannot get the data-remote attribute to render correctly. Is there a bug in my code?

现在这个code:

<%= button_to "Test", :action => "test", :remote => true, :form_class => "test_button" %>

得到此HTML:

yields this HTML:

<form action="/cloud_status/test?form_class=test_button&remote=true" class="button_to" method="post">

每的API规范的它应该渲染这样的:

Per the API specs it should render this:

<form action="/cloud_status/test" class="test_button" remote="true" method="post">

我在想什么?

推荐答案

我相信文件实际上是不正确这里的一些例子。让你正在寻找的输出的方法是:

I believe the documentation is actually incorrect here in some of the examples. The way to get the output you are looking for is:

<%= button_to "Test", { :action => "test" }, { :remote => true, :form_class => "test_button" } %>

:远程:form_class 应成为其中的一部分的 html_options 散,这是 button_to 方法的第三个参数。

The :remote and :form_class should be part of the html_options hash, which is the third parameter of the button_to method.

第二个参数可以是一个字符串散列。当它是一个字符串它当作一个URL时,它的散列它被传递给 url_for 来建立相应的URL。

The second parameter can either be a String or Hash. When it's a String it's treated as a URL and when it's Hash it is passed to url_for to build the appropriate URL.