Questions tagged [ransack]

Ransack is a Ruby gem that enables object-based searching against an application's models.

Ransack enables the creation of both simple and advanced search forms against an application's models.

It is a rewrite of MetaSearch, though while it supports many of the same features as MetaSearch, its underlying implementation differs greatly from MetaSearch, and backwards compatibility is not a design goal.

The Ransack Github repository is https://github.com/activerecord-hackery/ransack#readme

759 questions
9
votes
1 answer

Ransack, find record that has all related records

I have a recipe model which has_many ingredients and each ingredient belongs to an item. In my advanced search form, I would like a user to select multiple ingredients and let Ransack find a recipe that contains all the ingredients selected by the…
bo-oz
  • 2,842
  • 2
  • 24
  • 44
9
votes
3 answers

Activeadmin: how to filter for strings that match two or more search terms

Let's say I've got User class with an :email field. And let's say I'm using activeadmin to manage Users. Making a filter that returns emails that match one string, e.g. "smith", is very simple. In admin/user.rb, I just include the line filter…
dB'
  • 7,838
  • 15
  • 58
  • 101
9
votes
1 answer

Combine search predicates in Ransack

How can I implement the equivalent of :name_eq_or_description_cont, which combines _eq and _cont predicates into the same search key, so that I can create a search field in the form as: <%= search_field_tag :item, :name_eq_or_description_cont %> ?
tapdancer
  • 389
  • 2
  • 12
9
votes
1 answer

How to fix Ransack undefined method "_eq", when using ActiveAdmin with ":through" relationships in your model?

I have a Rails 4.0.1 application, using gems activeadmin 1.0.0.pre and ransack 1.1.0. Using ActiveAdmin, I have many errors like this one : NoMethodError in Admin::MyModel#action Showing [...]/views/active_admin/resource/action.html.arb where line…
Eric Lavoie
  • 5,121
  • 3
  • 32
  • 49
9
votes
2 answers

Rails 3.1 Ransack HABTM

Is HABTM supported by Ransack? Having the models: Shop HABTM Categories Category HABTM Shops Can I use ransack to search a Shop by a single category? What does the form look like?
9
votes
3 answers

ransack search form in header partial: No Ransack::Search object was provided to search_form_for

First of all, I'm new to RoR, so the answer may be obvious, in which case I apologize. I've looked around and haven't found anything that helps. I'm trying to have a search form at the header of every web page on my app that will search through the…
8
votes
1 answer

Ransack count sort order is wrong

I am using Ransack Gem and doing a count sort via counter cache. My attribute is an integer. I am calling it like this: <%= sort_link(@q, :people_count, "PEOPLE") %> The sort output I am getting is: [PEOPLE ASC] 1 2 0 0 [PEOPLE DESC] 0 0 2 1…
Gary Riger
  • 233
  • 2
  • 9
8
votes
3 answers

Ransack, Postgres - sort on column from associated table with distinct: true

I have an app that uses the Ransack gem and I'm converting it from Mysql to Postgres. In an instance where the sort column is from an associated table and the distinct option is set to true, Postgres throws this error: PG::InvalidColumnReference:…
8
votes
1 answer

How to use ransack on delegated fields

I have the following model class Position < ActiveRecord::Base belongs_to :position_name delegate :name, to: :position_name And this search form = search_form_for @search, url: '#', method: 'GET', html: {id: nil, class: "term_search_form"} …
Boti
  • 3,275
  • 1
  • 29
  • 54
8
votes
6 answers

searching records between start date and end dates for ransack

Hi i am using ransack + kalendae_assets gem for searching records in between start date and end date for this i am using ransack PREDICATES by referring https://github.com/ernie/ransack/blob/master/lib/ransack/constants.rb here is my code <%=…
r15
  • 486
  • 1
  • 8
  • 22
8
votes
3 answers

Ruby on Rails Ransack Datetime to date search

Like carvil I have in my model a datetime for created_at although I wanted the "equals" predicate to compare the created_at and a date (like '2012-09-26'). So I added in my model (in order to add casted attributes and take off the old…
user1700764
  • 81
  • 1
  • 3
7
votes
1 answer

Using Meta Search or Ransack with Geocoder

I've created a form that supplies search criteria: = search_form_for @q do |f| %h3 Search: = f.label :category_id %br = f.collection_select :category_id_eq, Category.all, :id, :name, :include_blank => true %br = f.label…
user970203
  • 91
  • 2
7
votes
1 answer

How to get Condition Group in Ransack?

I am using advanced search in Ransack which has default AND. I have made it as OR by putting .try(:merge, m: 'or')) @search = Data.search(params[:q].try(:merge, m: 'or')) but I am not able to get the AND/OR drop down as Condition Group like shown…
iCyborg
  • 4,699
  • 15
  • 53
  • 84
7
votes
0 answers

How to do a ransack search on has_one association and sort by it's existance?

I have two models with has_one and belongs_to associations. I want to sort the model with has_one depending on whether the associated object exists. I can currently sort for example by associated object field. Here is the simplified code: class A <…
user1167937
  • 441
  • 1
  • 8
  • 18
7
votes
2 answers

Rails time select to show only hour?

How do I make Rails time select to show only the hour part without the minutes? Basically what I want is to show a time filter with start_time and end_time and use Ransack gem to filter the query. # db create_table "schedules" t.time "start_time" …
hsym
  • 4,217
  • 2
  • 20
  • 30
1
2
3
50 51