-
-
Save RafaelMCarvalho/51924ff19dfce4942f5c946a4927d296 to your computer and use it in GitHub Desktop.
Ransack with JSONB query for array values (or condition)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Edition < ActiveRecord::Base | |
scope :distances_any, -> (*distances) { | |
where("distances ?| array[:values]", values: distances) | |
} | |
private | |
def self.ransackable_scopes(auth_object = nil) | |
%i(distances_any) | |
end | |
end | |
> Edition.ransack(distances_any: ['short', 'long']).result.to_sql | |
SELECT "editions".* FROM "editions" WHERE (distances ?| array['short','long']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using PostgreSQL and jsonb with Ruby on Rails
http://nandovieira.com/using-postgresql-and-jsonb-with-ruby-on-rails