Quantcast
Channel: Filtering in RailsAdmin using integer field of a belongs_to association - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Filtering in RailsAdmin using integer field of a belongs_to association

$
0
0

I'm attempting to configure "fields searching" on my User model using RailsAdmin and a belongs_to association, called Budget.

class User < ActiveRecord::Base  belongs_to :budgetendclass Budget < ActiveRecord::Base  has_many :usersend

The Budget object has a field price_in_dollars of type Integer.

In RailsAdmin, viewing the Budget object, I can click "Add filter" and choose "Price in dollars", which allows filtering using "Number" or "Between ... and ...", specifying a range.

I want to use similar filtering on my User model to filter by Budget, using the price_in_dollars column.

The RailsAdmin List documentation states:

Belongs_to associations:

  • will be searched on their foreign_key (:team_id)
  • or on their label if label is not virtual (:name, :title, etc.)
  • you can also specify columns on the targeted table or the source table

Based on this, I added this block to my User model:

rails_admin do  list do    field :budget do      searchable [:price_in_dollars]    end  endend

With this block, I can now enter a value such as "500" and filter using "contains" or "is exactly", and the price_in_dollars column is used, rather than the foreign key ID.

However, I do not have the ability to filter by a range, as I do when going to the Budget admin page directly.

Is there a way to force the filtering menu to use the options specific to a number or integer? It appears that it may be treating it like a string data type regarding filtering.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images