ransack

Ransack search, how to search for each word by splitting input search parameter

偶尔善良 提交于 2020-01-15 07:11:48
问题 I am currently experimenting using the ransack gem to conduct a search on a model in Rails. As it stands I am using the basic setup. Controller: def index @q = Person.search(params[:q]) @people = @q.result(:distinct => true) end View: <%= search_form_for @q do |f| %> <%= f.label :name_cont %> <%= f.text_field :name_cont %> <%= f.submit %> <% end %> I have managed to find lot of information about conducting searches on multiple fields, however, I haven't managed to find anything to help me to

Setting default search parameter on Ransack for rails

浪子不回头ぞ 提交于 2020-01-12 03:25:05
问题 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 completion date which either has a date in it or is null (unfinished). Currently, the search itself works great. I would like to make it so that the index page loads up showing only the unfinished work, but I also want it to work so that when someone

Ransack, find record that has all related records

丶灬走出姿态 提交于 2020-01-11 01:41:16
问题 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 user. I tried the following searchfield: = f.collection_select(:ingredients_item_id_in, Item.all, :id, :name, {}, {multiple: true}) But logically, this results in all recipes being shown that contain any of the selected ingredients. changing

Search for a null value using Ransack 'eq' predicate

老子叫甜甜 提交于 2020-01-03 15:58:37
问题 Using the 'eq' predicate with a blank value, Ransack will cancel out that predicate. Which is obviously handy to have an "All" option in your select. But what if I want to add an option in my <select> for null values too ? In order words how to produce the SQL query SELECT * FROM spree_orders WHERE order_cycle_id = NULL using the 'eq' predicate. My test code (with results) is below. What I would like is to filter out the Order s where order_cycle_id == nil Spree::Order.search(order_cycle_id

Searching multiple fields with Ransack

强颜欢笑 提交于 2020-01-02 10:58:19
问题 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.

Searching by full name with Ransack

烂漫一生 提交于 2020-01-02 10:19:46
问题 I have a Ransack form on a project I inherited that looks like this: <%- ransack_form_options ||= {} -%> <%- search_field_options ||= {} -%> <%- search_field_options.merge! autocomplete: "off", id: "q" -%> <div class="search-form"> <%= search_form_for(@q, ransack_form_options) do |f| %> <%= f.text_field search_on, search_field_options %> <%= f.submit 'Search' %> <%= button_tag '', class: 'cancel-search' %> <% end %> </div> The value of search_on is student_first_name_or_student_last_name_or

Rails 3.1 Ransack HABTM

妖精的绣舞 提交于 2020-01-02 01:45:07
问题 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? 回答1: I think the field you're trying to use would be :categories_id_eq Usage would be something like this <%= f.label :categories_id_eq, "Category" %> <%= f.collection_select :categories_id_eq, Category.order(:title), :id, :title %> 回答2: You should be aware that there are gotchas: while this workds fine :categories

Search multiple models at once with Ransack

烂漫一生 提交于 2019-12-29 17:47:05
问题 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 , Project , User and their defined attributes. I wanted to use Ransack because I already use it on the Work model in a different area of the app. I think I don't quite understand Ransack yet and the documentation always points out that you have to

Search multiple models at once with Ransack

 ̄綄美尐妖づ 提交于 2019-12-29 17:45:12
问题 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 , Project , User and their defined attributes. I wanted to use Ransack because I already use it on the Work model in a different area of the app. I think I don't quite understand Ransack yet and the documentation always points out that you have to

How to fix undefined method `form_with' in my search bar when building out Global Autocomplete Search?

£可爱£侵袭症+ 提交于 2019-12-25 15:55:31
问题 I get a strange error when trying to run a global autocomplete search across multiple models in my rails App and leveraging the easy-autocomplete jquery library along with the ransack gem for search. Specifically, I believe the error is in my navbar page as I get this error when I try to run a query- undefined method form_with for #<#<class:0x007f875a6f8b58>:0x007f87600e0aa8> I decided to hack away and switch form_with for form_tag but then I get an error on the line immediately below