In my index.erb
, I've created a search bar with the following code:
<nav>
<div class="nav-wrapper">
<form>
<div class="input-field">
<input id="search" type="search" placeholder="Search..." required>
<label for="search"><i class="mdi-action-search"></i></label>
<i class="mdi-navigation-close"></i>
</div>
</form>
</div>
</nav>
Now, I want to implement functionality so that this search bar can query my Sequel Database using a GET method in my app.rb
. However, I'm facing a few challenges.
Issue 1:
How do I capture and store the user's input from the search bar into a variable that I can then utilize in my GET method in app.rb
? Essentially, how can I retain the search query entered by the user?
Issue 2:
Is there any naming convention I should follow when defining the GET method in my app.rb
file?
Issue 3:
For database querying, I aim to use the .where()
method. In my model.rb
, I have a class called Town
with data collections which I intend to search through. Would my code snippet look like this in app.rb
?
@towns = Town.where(:name => @variable_from_part1)
Considering the input gathered from Issue 1, how can I effectively perform a search on my Sequel database based on the user's search query and display the results on the webpage?
Your assistance is greatly appreciated!