Search Bar In Rails

Yisroel Malamud
1 min readSep 13, 2019

First define methods in the controller

def search_people 
end
def found_people
@my_appts = current_le.appointments
@appointments = @my_appts.where(date:params[:date])
end

Create a view that is an empty form that finds data base on the user input

<% @appointments.each do |appointment| %> 
<li> <ul> <%= appointment.le.first_name %> </ul> <ul>
<%= appointment.client.name %> </ul> </li>
<% end %>
<%= form_tag("/search_appts", method: "post") do %>
<%= label_tag(:date, "Search for:") %> <%= date_field_tag(:date) %> <%= submit_tag("Search Appts") %>
<% end %>

Create routes so that the user can navigate to the path

get 'search_appts', to: 'appointments#search_appts', as: 'search_appts' post 'search_appts', to: 'appointments#found_appts'

--

--