Reputation: 587
I have 2 models University
and Course
. There is a has_many through relationship between both.
I am using Ranstack for search queries on the University
model as following:
<%= search_form_for @search do |f| %>
<div class="field">
<%= f.label :title_cont, "University name" %>
<%= f.text_field :title_cont %>
</div>
<div class="field">
<%= f.label :courses_course_type_in, "Course type" %>
<%= f.select :courses_course_type_in, Course.course_type.options, {} %>
</div>
<% end %>
and in my controller i have:
@search = University.search(params[:q])
@universities = @search.result
The :courses_course_type_in
is well understood in the query in the sense that i get only the universities that offer that specific type of courses(let's say graduate courses).
But in the other hand, when i come to display the courses, @universities.courses contains all courses of all the types available(graduate , undergrade, certificate, continuing education...).
Is there an easy way ( in ransack preferably ) to get only the wanted courses in @universities.courses ? (graduate in this case)
Thanks!
Upvotes: 4
Views: 2972
Reputation: 2135
Did you try with :
<%= f.select :courses_course_type_eq, Course.all.collect{|c| [c.course_type, c.course_type]} %>
Upvotes: 0