=button_to does not generates form if already in an other form

forms, haml, ruby-on-rails

Solution

HTML doesn't actually allow for forms to be nested. Some browsers do, but you will see some crazy behavior in others. Is the HTML you are showing the raw output or the computed DOM from firebug?

The preferred way to handle this case is to move your `button_to` outside the other form. If you're cool with JS-only options, you can use `link_to :method => :post` and style the link to look like a button.

Problem

Using the same form partial in both create and edit in my case new and preview. partial looks somewhat like this (I use HAML) ``` =form_tag ({:action => params[:action]}, :multipart => true) =text_field :newsletter, :title =text_area :newsletter, :body =file_field :newsletter,:attachment -if params[:action] == "preview" =button_to "select contacts and send", :action => "contacts" =submit_tag "save and preview" ``` but in the html-output is ``` ... <input type="submit" value="select contacts and send"/> <input type="hidden" value="rwYnZlEpWV4dR89zjgprEALBYmP0xqM3lnKt9JDLyak=" name="authenticity_token"/> <input type="submit" value="save and preview" name="commit"/> ... ``` why does the button_to not generate the button-to form? a solution is to keep the button outside the partial and only 1 per form, but how can I have 2 buttons in the same form? edit: another workaround would be a hidden checkbox that is set by javascript if the button_to is pressed and submits the form, separating them in the controller

Original source