ransack

Gem Ransack doesn't return any results when searched with full name

旧巷老猫 提交于 2019-12-06 06:22:23
问题 I'm using Ransack with Rails 3. My views: <%= search_form_for @search do |f| %> <%= f.text_field :first_name_or_last_name_or_company_cont, :style => 'width:150px;padding-top:6px;' %><p class="button"> <%= f.submit "Search by name or company" %></p> <% end %> My schema: create_table "users", :force => true do |t| t.string "first_name", t.string "last_name" on the User model I have: def full_name "#{self.first_name} #{self.last_name}" end Working on the console. If I have user with first_name =

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

此生再无相见时 提交于 2019-12-06 02:37:20
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 open ticket) expected SQL statement: SELECT * FROM tickets WHERE ... AND (user_id=5 OR user_id IS NULL)

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

浪子不回头ぞ 提交于 2019-12-05 23:17:44
问题 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: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list The Ransack github page says that, in a case like this, "you're on your own." What's the best - any! - strategy for handling this scenario? q = Contact.includes(:contact_type

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

喜你入骨 提交于 2019-12-05 04:55:30
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 :email This gives me a filter widget that does the job. However, this filter doesn't let me search for the intersection of multiple terms. I can search for emails containing "smith", but not for emails containing both "smith" AND ".edu". Google tells me that activerecord uses Ransack under the hood, and the Ransack demo has an 'advanced' mode that

whitelisting deeply nested strong parameters in rails

一曲冷凌霜 提交于 2019-12-04 21:14:16
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 params.require(:course_listing).permit({ q: { c: [{ a: [:name] }, :p, { v: [:value] }] } }) end I ended

Rails - Saving Ransack Query for later use

£可爱£侵袭症+ 提交于 2019-12-04 17:06:36
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 recreate the search by passing the query to ransack, but it does not seem to be working. The search pulls

How to use Ransack Aliases

蓝咒 提交于 2019-12-04 13:00:26
I am trying to implement aliases with Ransack to make my URL search query shorter. According to the docs: https://github.com/activerecord-hackery/ransack#ransack-aliases class Post < ActiveRecord::Base belongs_to :author # Abbreviate :author_first_name_or_author_last_name to :author ransack_alias :author, :author_first_name_or_author_last_name end However when i use it in my model, i get a undefined method `ransack_alias' for #<Class:0x007f9376f176e0> As I understand, ransack_alias appeared in the master branch of the ransack, in 1.7.0(current stable) it was not implemented. You should use the

How can I save Ransack searches to the database?

我的未来我决定 提交于 2019-12-04 12:56:38
问题 I'm trying to save Ransack searches to the database. I believe I should be able to just store the params[:q] value, then append that to the search URL when I want to recall the search. I don't know how to save the params[:q] value, though. The URL that Ransack creates is something like this: http://site.com/search?utf8=%E2%9C%93&q%5Bone%5D=something&q%5Btwo%5D=&q%5Bthree%5D=&q%5Blow_number%5D=0&q%5Bhigh_number%5D=300000&q%5Bfour%5D=&commit=Search My route to the action that will save the

Gem Ransack doesn't return any results when searched with full name

我的未来我决定 提交于 2019-12-04 12:09:36
I'm using Ransack with Rails 3. My views: <%= search_form_for @search do |f| %> <%= f.text_field :first_name_or_last_name_or_company_cont, :style => 'width:150px;padding-top:6px;' %><p class="button"> <%= f.submit "Search by name or company" %></p> <% end %> My schema: create_table "users", :force => true do |t| t.string "first_name", t.string "last_name" on the User model I have: def full_name "#{self.first_name} #{self.last_name}" end Working on the console. If I have user with first_name = "Foo" , last_name = "Bar" , when I search with either one, I get the results as expected. When I

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

你。 提交于 2019-12-04 05:07:40
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: ERROR: for SELECT DISTINCT, ORDER BY expressions must appear in select list The Ransack github page says that, in a case like this, "you're on your own." What's the best - any! - strategy for handling this scenario? q = Contact.includes(:contact_type).search q.sorts = ['contact_type_name asc'] q.result(distinct: true) PG::InvalidColumnReference: ERROR