I have two models, book and course. In the books_controller I have a search method to find books by their ISBN.
def searchbook
@searchedbook = Book.find_by_isbn(params[:q])
end
There is an input field in the index page that displays all the books. So my index.html.erb has this:
=form_tag({controller: "books", action: "searchbook"}, :method => :get) do
.search_field
%p
Search Using ISBN:
=text_field_tag :q
=button_tag 'Go' , class: 'search-button' , type: :submit
%br
I have added this to my routes:
match 'searchbook', to: 'books#searchbook', via: :get
I just realized that my searchbook.html.erb is exactly the same as the show.html.erb. How can I get show.html.erb to render the results from searchbook