ransack

Searching Multiple Models with Ransack Rails 4

徘徊边缘 提交于 2019-12-12 09:53:20
问题 I'm trying to figure out how to search multiple models with Ransack. The goal is to have the search form in my shared header. I'm using a combination of their documentation, an old rails-cast, SO questions, and some code a friend shared with me. Right now I think it works, although I'm not sure because I can't get the results to show on my index page. First, I created a search controller: class SearchController < ApplicationController def index q = params[:q] @items = Item.search(name_cont: q

Does Ransack support the same polymorhpic belongs_to associations in its searches as MetaSearch does?

时间秒杀一切 提交于 2019-12-12 09:52:56
问题 I am migrating from the MetaSearch gem to the Ransack gem for an upgrade to Rails 3.1 and I am having problems with my searches for polymorphic associations. The existing MetaSearch syntax isn't working for Ransack, but I couldn't find any documentation mentioning any syntax changes. Or whether this feature is supported in Ransack. For example, from the MetaSearch github page, given the following classes: class Article < ActiveRecord::Base has_many :comments, :as => :commentable end class

How to get Conditional Groups in Ransack?

旧城冷巷雨未停 提交于 2019-12-12 04:13:17
问题 Using Railscast and Ransack demo code, I am able to build Advanced Search like this The drop down "all/any" comes from <%= f.combinator_select %> and it works but I need Conditional Groups with (X AND Y) OR (A AND B) AND (M OR N) etc which I am not able to get. I saw the Ransack Demo example multiple times but it is using Rails 5 and I am not very clear with some part of it. Here is my code in Rails 4, can you tell me how to get Conditional Grouping ? routes.rb resources :data do collection

Using Ransack to sort attributes for parent of parent

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 11:49:12
问题 I know how to use Ransack's awesome sort_link method for parent attributes, but when I extrapolate the same logic to the attributes of the grandparent, it's not working (I can click the link, just no sorting happens). Hierarchy goes like this: Signup has_many Request has_many Transaction . I'm searching in from the Transaction perspective. Controller code: def index @q = Transaction.ransack(params[:q]) @transactions = @q.result.includes(:request => :signup) end View code: <th><%= sort_link(@q

Ransack search and translations

那年仲夏 提交于 2019-12-11 10:06:19
问题 I´m trying to make ransack work on a model that has an association with a translation table. Translations are managed by globalize gem. The problem is when I try to search with ransack in model table in :name column, it shows nothing because the :name information is stored in another table. Any clues how can I make ransack search in the association translation table? I know there is the possibility of using ransackers, but I have no idea which code to put in them. 回答1: Globalize gives you a

Undefined method error for filtering by age using Ransack gem

一曲冷凌霜 提交于 2019-12-11 07:26:53
问题 I am trying to filter results by age using ransack, but ransack is giving me an undefined method error. I have the Users DOB in my database and in my users model I have an age method that calculates the age of the user. It works perfectly fine and I am able to call the users age like this: @user = User.find(1) @user.age Now for ransack I have the following in my controller: def index @search = User.search(params[:q]) @users = @search.result end In my view, I have: <%= search_form_for @search

Ransack search error

故事扮演 提交于 2019-12-11 06:45:19
问题 I am using Rails 4.2.5, Ruby 2.2, ransack. I am trying to implement search functionality using Ransack. I have something like: These code are in abc_controller.rb: def checked_users emails = ["abc@abc.com", "a@a.com", "b@b.com"] users_list = User.where("email in (?)", emails) @q = users_list.ransack params[:q] end These are the code in checked_users.html.haml: (Ignore the url path here. Its correct, for now I have changed it) = search_form_for @q, url: checked_users_path(some_id: id) do |form

Ransack Undefined Method _path Rails 4.2.1

北城以北 提交于 2019-12-11 03:54:41
问题 I'm working on a very simple CRUD Asset Management app and I want to use Ransack. I think I have this setup properly in my view and controller but each time the index view is hit I get the exception: undefined method assets_path' for #<#:0x007fa5f353e9e0>` Here is my view: index.html.erb <div class="pull-right"> <%= search_form_for @q do |f| %> <%= f.search_field :asset_name_cont, placeholder: 'Search...' %> <% end %> <table class="table table-striped"> <thead> <tr> <th>Asset Number</th> <th

Passing local variables down Partial hierarchy in Rails 4 for Ransack associations

*爱你&永不变心* 提交于 2019-12-11 03:38:57
问题 I'm trying to implement a search and sort form on all of my model's index pages using Ransack. I would like to do this as DRY'ly as possible so I created three partials in my views/application folder: views/application/_table_search_and_sort_form.html.erb views/application/_condition_fields.html.erb views/application/_sort_fields.html.erb The code for each is as follows: views/application/_table_search_and_sort_form.html.erb <div> <%= search_form_for table_search_and_sort_form do |f| %> <%= f

Ransack search string arrays stored in db

一世执手 提交于 2019-12-11 03:32:55
问题 I'm trying to search using ransack for articles. In one of my question in how to get the articles based on their tags, I found out how to do so: Find articles where array Now I just want to do the search with ransack but I get an error I have it like this <%= search_form_for @q do |f| %> <div class="row"> <div class="col-md-2"> <%= f.label :tags_in %> <span data-toggle='tooltip', data-placement='right', title='Una o dos palabras máximo para expecificar lo que está buscando' class="glyphicon