jeudi 18 novembre 2021

Rails Ransack gem: search for multiple values with one condition

I use ransack gem and I have a select field event_id,if choose option Event Online will search with multiple values. This is my query:

ransack("job_name_cont" => job_name, "event_id_eq" => event_id).result

event_ids is string or array - eg: 90 or [ 145, 147, 148 ]. When search with option Event Online, the result returning errors:

[1] pry(Job)> ransack("job_name_cont" => job_name, "event_id_eq" => event_ids).result 
NoMethodError: undefined method `to_i' for [145, 147, 148]:Array
Did you mean?  to_s
               to_a
               to_h

My model:

class Job < ActiveRecord::Base
  belongs_to :event
end

class Event < ActiveRecord::Base
  has_many :jobs, dependent: :destroy
end

How can i search with event_id is array?

Aucun commentaire:

Enregistrer un commentaire