Search code examples
htmlrubyformssinatra

Multifunction/Nested Forms?


Is it possible to create multifunction/nested forms with sinatra?

Right now I am doing something like this:

<form action="/section/<%= section.id %>" method="post">

  <input type="hidden" name="_method" value="put">
  <input name="heading" value="<%= section.heading>">
  <input type="submit" name="update" value="Update Section">

  <form action="/section/<%= section.id %>" method="post">
    <input type="hidden" name="_method" value="delete">
    <input type="submit" name="delete" value="Delete Section">
  </form>

</form>

With the second <form> section both submit buttons point to delete /section/:id. Without the second <form> both submit buttons point to put /section/:id.

I would like to have a single form with a button for Updateing and Deleting, but it seems that the any submit button has the value of whatever the last html verb used. Is this even possible to do with sinatra? or am I stuck using <a> links instead of buttons?


Solution

  • Now I know this now not valid syntax, javascript is required for this kind of magic.