1

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?

blundin
  • 1,603
  • 3
  • 14
  • 29

1 Answers1

2

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.

Marc Baumbach
  • 10,323
  • 2
  • 30
  • 45
  • +1, it's not always clear which hash options belong in (or that there is even the possibility of there being two hashes because of Ruby's implicit hash sugar). – Dave Newton Feb 06 '13 at 17:59
  • 1
    FYI: I've delivered a change to docrails to hopefully resolve this confusion: https://github.com/lifo/docrails/commit/741b291d660b298c0e39ce15e266f7d2cdfa8e2d – Marc Baumbach Feb 06 '13 at 18:29