Reputation:
I have four buttons, and everytime I click the button it should send a post request (I'll show my code below).
This is my books controller.rb
post '/all?' do
@books = # Books here
haml :'books/index', locals: {books: @books}
end
post '/fantasy?' do
@fantasy = # Fantasy books here
haml :'books/index', locals: {fantasy: @fantasy}
end
And this is my index.haml
file:
%form{method: 'POST', action: "books/all"}
%input.btn.btn-md{type: 'submit', value: 'All Books'}
%form{method: 'POST', action: "books/fantasy"}
%input.btn.btn-md{type: 'submit', value: 'Fantasy'}
However, what happens is the following:
(1) URL: localhost:8080/books
(2) I click on the all
button
(3) URL: localhost:8080/books/all
(4) I click on the fantasy
button
(5) URL: localhost:8080/books/books/fantasy
This is the problem - how can I get it so on the second button click, it goes to localhost:8080/books/fantasy
instead? I'm sure its a simple fix just not sure how. Thanks.
Upvotes: 0
Views: 36