Ransack the right search filter in association models

I have 2 models Universityand Course. There is a has_many relationship between them.

I use Ranstack for search queries in the model Universityas follows:

<%= 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:

@search = University.search(params[:q])
@universities = @search.result

:courses_course_type_in well understood in the request in the sense that I only receive universities offering certain types of courses (say, graduate courses).

But on the other hand, when I come to show courses, @ university.courses contains all the courses of all available types (graduate, sub-title, certificate, continuing education ...).

Is there an easy way (preferably in ransack) to get only the right courses at @ university. courses? (graduate in this case)

Thank!

+4
1

:

<%= f.select :courses_course_type_eq,  Course.all.collect{|c| [c.course_type, c.course_type]} %>
0

Source: https://habr.com/ru/post/1536845/


All Articles