这是为什么button_to渲染不正确Rails中3.2.11? [英] Why is this button_to rendering incorrectly in Rails 3.2.11?

查看:118
本文介绍了这是为什么button_to渲染不正确Rails中3.2.11?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在工作中的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.

这篇关于这是为什么button_to渲染不正确Rails中3.2.11?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆