Questions tagged [ransack]
Ransack is a Ruby gem that enables object-based searching against an application's models.
756
questions
0
votes
1
answer
13
views
After applying a ransack date-field filter same output tickets are repeating instead of one
Current result: In deadline filter, it is considering the first box as "from date " and the second as "to date" and on applying the filter same tickets are repeating
Expected ...
0
votes
1
answer
40
views
How to pass user's browser geolocation (from javascript) to rails?
I'm currently setting the user's coordinates (latitude and longitude) using request.location.coordinates, but the location is not accurate enough. I want to use the user's browser geolocation instead.
...
0
votes
1
answer
30
views
ActiveAdmin filter via activerecord association
In a rails project I have two models:
# id
# email
# password
class User < ApplicationRecord
has_many :guests, dependent: :destroy
end
# id
# name
class Guest < ApplicationRecord
belongs_to ...
0
votes
1
answer
43
views
How do I set a default sort parameter in Ransack to avoid error: "undefined method `[]' for nil:NilClass"?
This is a beginner's question, and hopefully will have a simple answer!
I have a Rails 7 app that includes a parks index page. I am using Ransack that lets the user sort by distance, rating, or name. ...
1
vote
1
answer
33
views
Ransack: Two filters each work on their own but not together, PG::UndefinedTable error
In my Rails 7 app I have parks and users. Users can mark parks as favorite and visited. I want to allow the currently logged in user to filter parks based on both whether they've favorited the park, ...
0
votes
0
answers
30
views
Ransack: How to combine both '_in' and '_not_in' filter options in one dropdown?
In my Rails 7 app I have parks and users. Users can mark parks as visited. I want the currently logged in user to be able to filter based on whether or not they've visited the park.
I made the filter ...
0
votes
0
answers
32
views
Rails Ransack gem slider
I want to be able to performa range search with ransack. I was hoping I could do this with a slider that has two thumbs. I'm thinking that the _in predicate would be perfect for a situation like this. ...
0
votes
0
answers
7
views
Pundit Policy Scope with Ransack query
I am trying to use Ransack to filter records that have an applicable policy_scope from Pundit.
class ItemsController < ApplicationController
def index
@q = policy_scope(Item).ransack(params[:...
0
votes
0
answers
60
views
How do I sort by distance from user, based on user's location?
I have a Rails 7 app in which users can search, sort, and filter to find parks and nature reserves. I'm using the Ransack gem.
I have calculated the distance of each park from the user based on the ...
0
votes
1
answer
46
views
include only scoped records in ranscak search instead of all records
I have Employee applications class with each Employee has to select in the application a Software that he can use, and then I have a search form using ransack, but when I search for the employee ...
0
votes
1
answer
59
views
New search form partial is redirecting to my main index page for the model
I have an events model and I have an address field where I have some geolocation logic being implemented. On my main index page, I'm rendering a search form partial that works just fine to be all to ...
0
votes
1
answer
44
views
Issue constructing a has_many relation with scope using multiple join tables
I have a tag system on multiple models that are linked together.
The system works like this:
A Top has many Middles
A Middle has many Lows
Tops, Middles and Lows have many Tags
A tag associated to ...
1
vote
0
answers
25
views
Select every query from a set which results contain a record
I'm working on a Rails 6.1 app that has these two models:
# == Schema Information
#
# Table name: publications
#
# allow_comments :boolean default(FALSE)
# created_at :...
0
votes
2
answers
169
views
How to search with Ransack with multiple items from an array
On my events index page, I have a search form that filters the records on the index page based on those search parameters through Ransack.
The search form currently works only when the dance styles ...
0
votes
1
answer
94
views
rails ransack filter by association model field
I want to find records by association model
Example:
User.includes(:orders).ransack(orders_id_eq: '1').result.to_sql
and result returns
SELECT users.* FROM users LEFT OUTER JOIN orders ON orders....
0
votes
0
answers
113
views
Rails Ransack, initialize from front end as an array
In the React front end, the ransack parameter is initialized like so:
const statusFilter = 'ransack[status_in]=incomplete';
In the backend, I've got
@params["ransack"]&.each do |filter, ...
0
votes
1
answer
92
views
Rails ransack search condition
Is there a way to add a "condition" to a ransack search? I want to search through published Articles only.
Currently my code looks like this and is working perfectly. But it shows articles ...
0
votes
0
answers
43
views
sort_link asc desc not working for associated relation
I have a method full_name in owner.rb, I want to sort owner asc and desc in properties index, either it does asc or will do desc, but in this case, I have tried many ways to sort this but none of this ...
0
votes
0
answers
46
views
Search with Array of values Ransack
I'm working with ransack and using its form like
<%= search_form_for @search, url: box_index_admin_medleys_path do |f| %>
<div class="col-md-4 col-xs-12">
<div class=&...
1
vote
1
answer
58
views
rails implementing ransack search - routing configuration
Fairly new rails developer, and still trying to get my head around where things go and how to connect them.
I have a database of 'records', and am looking to search them. I found the ransack gem, ...
0
votes
0
answers
59
views
Arel and ransack, custom ransacker for sorting on average ratings
I am new to both ransack and arel, and not having luck with getting this to work.
I am trying to make custom ransacker on Tehnician model so I can sort by average rating on technicians index table. I ...
0
votes
0
answers
78
views
Custom ransack sort, if has association it will be placed at the beginning of the list and has no association will be placed at the end of the list
I was creating a custom scope wherein to be use in sort link. I was using ransack gem for this.
Model
Town [name, code]
has_many :comments, as: :commentable
Comment [commentable_type, ...
0
votes
1
answer
173
views
ActiveAdmin filter boolean with Nil Value
I use my Rails app to see if guests will participate to an event.
I have a Guest model that has a participate boolean.
This boolean is initialised as Nil for all new Guests. By initialising it in this ...
0
votes
0
answers
36
views
Search by minute in ActiveRecord Using Ransack
I have the following question, is it possible to create a query in ransack, where in the filter screen we enter a minute: EX: 04 or 53.
Soon all the records that were created in that minute will come, ...
0
votes
0
answers
102
views
Ransack custom sort_link record has_comments boolean value
Having 2 models which Town and Comment.
Model Setup:
class Town < ApplicationRecord
has_many :comments, as: :commentable
end
class Comment < ApplicationRecord
belongs_to :commentable, ...
0
votes
0
answers
58
views
Ransack multiple boolean search
I'm trying to filter with ransack two boolean attributes with the same select. Example:
Select:
All - (Field_1: any; Field_2: any)
Field_1: - (Field_1: true; Field_2: any)
Field_2: - (Field_1: ...
0
votes
0
answers
40
views
Add a new filter for class.name to table where is a multiplie models
In the project I linked most of the different models (e.g. User, Car, Gallery, Article ...) so that their common list is displayed in one view in the table.
I also created one global search for ...
0
votes
1
answer
33
views
Is there a way to query specific values from psql in Ruby Ransack?
I'm trying to optimize a report building function, and as it always does, the querying takes most of the time, so I try to speed it up a bit.
Now I found a solution for the problem, I'm just trying to ...
0
votes
0
answers
94
views
Ransack search with two belongs_to associations to the same model
I have the following models:
class Item < ApplicationRecord
belongs_to :category
belongs_to :manufacturer, class_name: "Origin"
belongs_to :purchased_from, class_name: "Origin&...
0
votes
0
answers
310
views
How do I add a filter to the Ransack search function in Rails?
I have implemented Ransack's search function, and now I need to add a filter to let the list filter according to the "status" of the drop-down menu -- that is, prompt: t('all_status') in the ...
1
vote
1
answer
178
views
How can I test a model's custom predicate? (Ransack search)
I have a model called Invoice with an amount_cents attribute.
I'm using Ransack gem to perform searching and want users to be able to search by integer amounts.
I added a custom predicate to my ...
1
vote
0
answers
274
views
How to filter status with Rails Ransack's filter?
I found a description in the Ranksack tutorial (https://activerecord-hackery.github.io/ransack/getting-started/sorting) about filters. I have used Ransack to complete the search and sorting functions. ...
0
votes
1
answer
56
views
How to apply i18n to Rails Ransack's sort_link
I'm using Ranksack to make search and form sorting functionality. Among them, I found that I can use sort_link to sort the table by "Name":
<th scope="col"><%= sort_link(@...
0
votes
1
answer
179
views
RAILS - Using Ransack as a filter. Is there a way for me to add a link to a page that leads to a filtered link?
I have a model for my Contracts and then another model for my Contract Status.
Right now when any contract is marked from active to inactive it creates a new item in my Contract Status page every ...
0
votes
0
answers
41
views
Link to Unknown action after pressing "submit" in Rails Ransack's search function
I'm using Ransack to make a Rails search function, and it's worth noting that I've defined an action named "list" in the controller to be the home page of the site.
When I press search (...
0
votes
1
answer
605
views
Is it possible for ransack to find all the related association items while searching with them?
Assume post has many categories and it has an N:N relationship and I want to search for all the posts that have a certain category AND all the categories for the resulting posts.
For example, if posts ...
0
votes
0
answers
217
views
NoMethodError (undefined method `ransack' for #<Class:0x000055725c12ba78>)
Tested throughly in dev and Ransack works as described. However in production I get the following error:
NoMethodError (undefined method `ransack' for #<Class:0x000055725c12ba78>)
Here's the ...
-1
votes
1
answer
287
views
Why Ransack doesn't show any search results
I refer to the official teaching and also read all the similar Q&A on Stackoverflow, but I am not using Pagy and AJAX, so it is not the same error.
I'm trying to search for the value of the name ...
0
votes
1
answer
145
views
Why shouldn't I use ransack to only simplify query generation?
I found this statement right at the beginning of ransack README.
If you're looking for something that simplifies query generation at the model or controller layer, you're probably not looking for ...
0
votes
0
answers
38
views
Persisting search queries
I'm using this code to persist my ransack filters when the user destroys the item.
# In application controller
def get_query(cookie_key)
cookies.delete(cookie_key) if params[:clear]
cookies[...
0
votes
0
answers
104
views
Rails sorting table through associated model
In my Rails 5 app I've got table which I want to sort by table headers. To do this I was thinking of using the ransack gem so I did some changes to my controller and view:
...
0
votes
1
answer
69
views
Rails 6 : use a HTML5 date field for a Ransack search filter
I have a list of appointments, with a ransack search field to filter by date. As of now, users have to type the date, like "12/02/2022". Elsewhere in the app, I'm using a HTML5 date selector,...
0
votes
1
answer
86
views
Check if a record has related records through Ransack. Rails
Given two models. In my case Course that has many Question.
I want to know if it's possible, through Ransack, to query only the courses that has questions related.
Thanks in advance
0
votes
1
answer
41
views
Ransack:Error - I'm trying to render nav bar with ransack search bar on every page but getting errors when I click on show, new page
I'm new to ruby on rails and I'm trying to build reddit clone. I'm trying to render nav bar with ransack search bar on every page and it works fine for the index page; but I'm getting errors when I ...
0
votes
0
answers
79
views
RubyOnRails how to create form for ransacker method with arguments?
I have a custom ransacker method called score
ransacker :score, args: [:parent, :number_one :number_two] do |parent, args|
(parent.table[:id] + parent.table[:id]) / (number_one + number_two)
...
0
votes
2
answers
511
views
RubyOnRails Custom SQL Query in Ransack gem Advanced Forms
Click on image to see view
Ransack generated following query SELECT "sheets".* FROM "sheets" WHERE ("sheets"."id" > 5)
but I want to implement formula in ...
0
votes
0
answers
84
views
How to order users by the number of user's posts in a particular category
I have 3 models,
User (has_many :posts)
Post (Belongs_to :user, has_many :categories through: :posts_categories)
Category (has_many :posts through: :posts_categories)
Now, I want to find and order ...
1
vote
1
answer
57
views
[Rails][Postgres] How to order users by most posts in a category?
I am struggling to achieve this
I have 3 models,
User (has_many :posts)
Post (Belongs_to :user, HABTM :categories)
Category (HABTM :posts)
Now, let's say I want to find and order all users who have ...
0
votes
1
answer
201
views
How do I validates input while using Ransack?
I created a search form with multiple search bars by using Ransack, and realized I'd still get search results leaving some input bars blank, even with validates codes in the model.
ticket.rb
class ...
0
votes
0
answers
75
views
How to apply sorting asc desc on 3rd level association using ranksack in Ruby
I am using ransack gem for searching which's working fine but I have search creteria in which I want to search order based on products title asc or desc in line items.
It does not work and returns:
...