I have a Devise "edit user" form in my Rails app. A User also contains a school_id. On my edit user form I have a section that shows what school the user is subscribed to. Next to the School name I have a button that sets the User's school_id to nil. However, since this is actually a form with a hidden field, the user can "Save changes" on the edit user form and it will set the school_id to nil because of the other form I have on the page.
Pseudo code:
edit user information
School: schoolname [button to remove school]
edit more user information
[Submit changes]
Button to remove school:
<% if current_user.school %>School: <b><%=link_to current_user.school.name, current_user.school %></b>
<%= form_for(@user) do |f| %>
<%= f.hidden_field(:school_id, :value => nil) %>
<%= f.submit "Remove school", class: "btn btn-danger btn-small" %>
<% end %>
Is there a way to achieve this without having to move the the Remove School button outside the form? It fits very nicely in the workflow but it causes issues since its now technically part of the edit devise user registration form. Any ideas?
Thanks!!