Why is this button_to rendering incorrectly in Rails 3.2.11?

二次信任 提交于 2020-02-05 05:54:21

问题


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?

Right now this code:

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

yields this HTML:

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

Per the API specs it should render this:

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

What am I missing?


回答1:


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" } %>

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

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.



来源:https://stackoverflow.com/questions/14735591/why-is-this-button-to-rendering-incorrectly-in-rails-3-2-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!