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
81
votes
2 answers

Remove order from ActiveRecord scope

I'm using rails ransack ( https://github.com/ernie/ransack ) to allow the users to filter and sort some records. I get the filtered and sorted records using traditional methods. @invoices = Invoice.search(params[:q]).result Now I would like to…
jrhicks
  • 14,759
  • 9
  • 42
  • 57
21
votes
2 answers

How to set defaults for ransack sorting?

To put simply enough, I'd just like to know if there's a way to set defaults for the sorting functionality using the Ransack gem? ie. Currently, I have the following when the page loads: But instead, I'd like to have the following defaults when the…
jlstr
  • 2,986
  • 6
  • 43
  • 60
20
votes
1 answer

Search multiple models at once with Ransack

I have a search form in the header of my app and I would like to use this search form to search through multiple models within the application. For example a request like /search?q=rails should trigger a search through multiple models like Work,…
Daniel
  • 4,082
  • 3
  • 27
  • 46
20
votes
2 answers

Rails + Ransack - Drop Down List Collection?

I am loving the ransack gem for its flexibility, however I am unable to get the standard collection_select to function properly. Perhaps someone can assist. Example: <%= collection_select(:expense, :project_id, Project.all, :id,…
Atari2600
  • 1,219
  • 2
  • 13
  • 26
15
votes
4 answers

Setting default search parameter on Ransack for rails

I've been wracking my brain over this but can't get it. I feel like the answer is probably obvious. What I'm trying to do is the following: I have an index controller which lists a series of Jobs which I can search using Ransack. Each job has a…
Alexander Moore
  • 467
  • 2
  • 5
  • 13
14
votes
2 answers

Custom search with ransacker

I'm trying to add a custom filter to ActiveAdmin which is powered by Ransack these days. Unfortunately, ransacker is not documented at all and from the few resources online I fumbled together the following (in the User model): ransacker :full_text,…
svoop
  • 3,318
  • 1
  • 23
  • 41
14
votes
3 answers

Ransack: How to use existing scope?

Converting a Rails 2 application to Rails 3, I have to replace the gem searchlogic. Now, using Rails 3.2.8 with the gem Ransack I want to build a search form which uses an existing scope. Example: class Post < ActiveRecord::Base scope :year,…
Georg Ledermann
  • 2,712
  • 4
  • 31
  • 35
13
votes
2 answers

Rails sorting associations with Ransack

first time poster. I am trying to sort a table of users using the Ransack gem and Kaminari for pagination. When I use name, id, etc. sorting works but when I try an association with posts_count, sorting breaks and won't work. Note: in the view,…
Sean Thomas
  • 131
  • 1
  • 5
12
votes
2 answers

Ransack exact match with array values

I have to perform a search on a database using ransack. A few columns in the database have data stored in serialized arrays. I want to match the exact data stored in the arrays with data sent by user to perform search (users' data are also arrays).…
thedudecodes
  • 1,479
  • 1
  • 16
  • 37
11
votes
2 answers

Converting a complex postgresql query/subquery to Rails activerecord syntax OR convert array to active record relation?

So I put quite a bit of time to write this query, and then found out the hard way that this is returning an array rather than an activerecord relation. DOH. This wouldn't be a problem, but i need to use Ransack on these results, which requires the…
Joel Grannas
  • 2,016
  • 2
  • 24
  • 46
11
votes
3 answers

Searching on an Enum Field with Ransack

I've got a table, 'jobs' with a enum field 'status'. status has the following enum set: enum status: [ :draft, :active, :archived ] using ransack, how do I filter the table for, say, all active records?
Will
  • 4,498
  • 2
  • 38
  • 65
11
votes
1 answer

Ransack, search multiple columns, one field, rails 3

I'm new to Ruby on Rails, and I'm creating my first site. I have a user model with 3 columns: firstname, lastname and email. Im using ransack to make a search engine, and i want to have one search field that will go through every column and display…
Remi Champ
  • 223
  • 1
  • 2
  • 6
10
votes
1 answer

How can ransack use pg_search?

I'd like to use ransack (via ActiveAdmin) to do full-text searches on a model. How can I get ransack to use pg_search for its query? I want to run queries that, among other query components, use pg_search functionality.
Eric
  • 5,815
  • 3
  • 25
  • 34
10
votes
1 answer

Ransack OR queries

I want to make a search for all fields that are NULL or have the value of -1 using ransack. search({:param_name_null => 1 }) will give the nulls search({:param_name_is_any => -1 }) will give the -1s How do i make an OR between these two using…
aharonidan
  • 183
  • 1
  • 5
10
votes
2 answers

Ransack gem choose predicate and custom predicate names

I'm a bit confused with using an advanced ransack search. I'm trying do make a custom search where not all table names can be selected as search terms and not all predicates are used. I used railscast as a tutorial for this but I can't find anything…
Jaro
  • 860
  • 9
  • 21
1
2 3
50 51