Pass selected <option> in <select> tag to next page in Rails -


i have created using following code

<select name="books"> <% books.each |book| %> <option value="<%= book.id%>"> <%= book.name %> </option> </select> <% end %> 

i have button on same page

<button>view book details</button> <button>delete book</button> 

now want take user different pages depending upon button clicks. when clicks on "view book details", want land him /book/view , if clicks on "delete book", want land him /book/delete

when land user desired page, want pass selected user using landing page. this

  • say, if user choose book-1, , clicks on "view book details", want /book/view?id=1
  • if user choose book-3, , clicks on "view book details", want /book/view?id=3
  • if user choose book-5, , clicks on "delete book", want /book/delete?id=5

how can ?

according code, come this:

 <%= form_tag "/book/view", method: :get %>    <%= select_tag "id", options_for_select(books.collect{|book| ["#{book.name} #{book.id}", book.id] }) %>    <%= submit_tag "view book details" %>  <% end %>   <%= form_tag "/book/delete", method: :delete %>    <%= select_tag "id", options_for_select(books.collect{|book| ["#{book.name} #{book.id}", book.id] }) %>    <%= submit_tag "delete book" %>  <% end %> 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

php - Find a regex to take part of Email -