Ruby on rails, Form buttons get their routes mixed up -


while making form in ruby on rails encoutered peculiar, submit button performs action of button in form.

<%=form_for(happening) |f|%>    <%=f.text_field :name, class:"updateinput" %>    <%=f.submit "save", class:"editbutton" %>    <%= button_to "delete", happening, method: :delete, class:"editbutton"%>    <input type="datetime-local" value="<%= happening.get_html_date %>"> <%end%> 

when click submit button in form, routed destroy action, rather update one. when remove deletebutton, routed properly.

does have explination this? thanks

you're seeing behavior because there's more meets eye when use button_to helper. button_to doesn't create button -- creates entire form, actual button serving form's submit button.

by including button_to helper within form, you're violating html's "no nested forms" rule , adding second submit button form overrides intended submit button. there's difference between submit button , input of type button in html, , mentioned already, button_to creates submit button.

if move button_to outside of form ahmad pointed out, you'll have un-nested forms , view should behave expected.

consult api doc additional details.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -