ransack

Scoping an association search with Ransack

会有一股神秘感。 提交于 2019-12-11 01:22:24
问题 I have a User model with an Enrollment model associated with it. A User can have many Enrollments but each Enrollment only has one Company . My Enrollment model has a flag_contractor boolean. So if I have a User search such as :enrollment_flag_contractor false I can get inconsistant results as I am trying to scope my enrolments for the current company (via the Apartment gem). For example I have a user that has an enrollment in two separate companies, one with flag_contractor = true and one

Make an OR with ransack

爱⌒轻易说出口 提交于 2019-12-10 13:08:23
问题 A basic questión, but I couldn't find something clear in the project page or the wiki. I have the following code: field = "secre" Position.search( {:description_cont => field, :code_cont => field}).result(:distinct => true).to_sql => "SELECT DISTINCT `positions`.* FROM `positions` WHERE ((`positions`.`description` LIKE '%secre%' AND `positions`.`code` LIKE 0))" But my query should be like: => "SELECT DISTINCT `positions`.* FROM `positions` WHERE ((`positions`.`description` LIKE '%secre%' OR

In form sorting using ransack gem not working

白昼怎懂夜的黑 提交于 2019-12-10 12:27:01
问题 I've been trying (unsuccessfully so far) to use the out of the box in-form sorting provided by the ransack gem, and the result of it unfortunately is an empty form. Here's what I've done so far: Controller: class LandingController < ApplicationController layout "landing2" def index @zones = Zone.all @zone_id ||= 1 @q = Property.search(params[:q]) @q.build_sort if @q.sorts.empty? end end View (partial): <%= search_form_for @q, :url => home_path, :html => { :method => :get } do |f| %> <%= f

Custom filter in rails ActiveAdmin using ransack

半世苍凉 提交于 2019-12-07 22:44:51
问题 I have created an activeadmin filter that has the following choices on filtering the table data in its drop-down menu. Choice A Choice B Choice C Choice D I want to add a fifth choice F that would either choice B or C (that is the results of both B and C). Choice A Choice B Choice C Choice D Choice F = either B or C The choices are stored in a table called Coupons in its title field (i created a row having the choice F). So far, I tried to employ a ransack to do the trick, without being quite

Rails gem Ransack -> search 'or condition' with 'is null' and a specific value (field=x OR field IS NULL)

狂风中的少年 提交于 2019-12-07 14:45:45
问题 I made a support ticket system for our supporters - programmed with ruby on rails (Ruby 1.9.3 Rails 3.2) There is a ticket model with a belongs_to association to users (supporter). I use Ernie's gem Ransack for searching. When the supporter searches his own tickets (handled by tickets_controller.index) he should also see the unassociated tickets in the search result (views/tickets/index) (in combination with the other serach conditions eg. "date" or something else) (So that he can take an

whitelisting deeply nested strong parameters in rails

≯℡__Kan透↙ 提交于 2019-12-06 15:23:12
问题 I'm trying to store a serialized Ransack search in a text column. It's deeply nested and I'm struggling coming up with permit call for it. Here's a sample hash: { "c"=>{ "0"=>{ "a"=>{ "0"=>{ "name"=>"column_1" } }, "p"=>"eq", "v"=>{ "0"=>{ "value"=>"value_1" } } }, "1"=>{ "a"=>{ "0"=>{ "name"=>"column_2" } }, "p"=>"cont", "v"=>{ "0"=>{ "value"=>"value_2" } } } } } How would you write a permit for that? This is my best guess for reading the doc but it isn't working. def course_listing_params

Custom filter in rails ActiveAdmin using ransack

大憨熊 提交于 2019-12-06 13:19:31
I have created an activeadmin filter that has the following choices on filtering the table data in its drop-down menu. Choice A Choice B Choice C Choice D I want to add a fifth choice F that would either choice B or C (that is the results of both B and C). Choice A Choice B Choice C Choice D Choice F = either B or C The choices are stored in a table called Coupons in its title field (i created a row having the choice F). So far, I tried to employ a ransack to do the trick, without being quite sure. //app/admin/user.rb filter :has_right_choice, label: 'Filter by the right choice', collection:

Rails - Saving Ransack Query for later use

和自甴很熟 提交于 2019-12-06 11:36:35
问题 I have successfully installed the Ransack gem and have it working in my app for both simple and advanced searches. I am trying to add a feature for users to "Save a Search". Essentially the idea is they can bookmark a search query, and access it later at any time. I set it up by creating a SavedSearch model. When a user saves the search it takes the params[:q] from their ransack search and stores it in the database. Later I pull this record from the database, and access the query. I try to

Searching multiple fields with Ransack

自古美人都是妖i 提交于 2019-12-06 08:53:41
I'm using Ransack to allow advanced searching on my users. Currently, the users have first_name , middle_name , and last_name columns. Here is my code: .field = f.attribute_fields do |a| = a.attribute_select ... How can I have a custom one called 'Name', that lets the user search through all three of the columns mentioned above? Note I would still like to keep the remaining attributes as options as well, such as email, phone number, etc. Please keep this in mind when determining an answer. Thilo I would suggest to provide a dedicated column for this search. While that might create redundant

Ransack: how to join table multiple times with different alias?

老子叫甜甜 提交于 2019-12-06 06:52:16
Suppose I have :items with a has_many association with :properties, then I can search for all items that have a property with name 'a_name' and value 'a_value' like this q: { properties_name_eq: 'a_name', properties_value_eq: 'a_value' } Now what if I want to search for all items that have a property with name 'a_name' and value 'a_value' and also a property with name 'another_name' and value 'another_value'? The following doesn't work as it joins the properties table only once q: { g: { '0' => { properties_name_eq: 'a_name', properties_value_eq: 'a_value' }, '1' => { properties_name_eq: