I'm trying to make a three input select menu that allows a user to filter down to one course in the database to select. So the user first selects the location, and based on that selection is given all the options of courses that are in that location. He can then press select and be brought to that course. The dynamic part has my mind bent a little. I'd love any help if possible. I understand some AJAX will probably be required but I'm lost on that end. Any advice please.
Code so far. View.
<div class="row no-gutters wow slideInUp" data-wow-duration="1s">
<div class="col-md-12 home-form">
<form class="form-inline">
<select class="custom-select mb-0 mr-sm-0 mb-sm-0">
<option selected>Location</option>
<%= @locations.each do |location| %>
<option value="<%= location.id %>"><%= location.header %></option>
<% end %>
</select>
<select class="custom-select mb-0 mr-sm-0 mb-sm-0">
<option selected>Course Type</option>
<%= @courses.each do |course| %>
<option value="<%= course.id %>"><%= course.course_type %></option>
<% end %>
</select>
<select class="custom-select mb-0 mr-sm-0 mb-sm-0">
<option selected>Course</option>
<%= @courses.each do |course| %>
<option value="<%= course.id %>"><%= course.title %></option>
<% end %>
</select>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
Controller just pulls in variable for all locations and courses.
Then models have associations as below.
course
belongs_to :location
location
has_many :courses, dependent: :destroy
I can see all the courses and locations from the dropdown but I need to be able to select a location and then only see courses that are in that location please. If any AJAX code is responded i'd love an explanation of what's happening in the code if you have time. Thanks a million.