Filtering in RailsAdmin using an integer belongs_to association field

I am trying to set up "search fields" on my User

model using RailsAdmin and an belongs_to

association called Budget

.

class User < ActiveRecord::Base
  belongs_to :budget
end

class Budget < ActiveRecord::Base
  has_many :users
end

      

The object Budget

has a price_in_dollars

type field Integer

.

In RailsAdmin, while browsing the object Budget

, I can click Add Filter and select Dollar Price, which allows filtering using Number or Between ... and ... specifying a range.

I want to use similar filtering in my model User

to filter by Budget

using a column price_in_dollars

.

The RailsAdmin list documentation says:

Belongs to associations:

  • will search for their Foreign_key (: team_id)
  • or on their label if the label is not virtual (: name ,: title, etc.)
  • You can also specify columns on target table or source table

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

:

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

      

With this block, I can now enter a value such as "500" and price_in_dollars

filter using "contains" or "exactly" and the price_in_dollars

foreign key identifier column is used price_in_dollars

.

However, I have no way to filter by range as I do when going directly to the admin page Budget

.

Is there a way to force the filter menu to use number or integer specific options? It looks like it can be thought of as a string datatype with respect to filtering.

+3


source to share


1 answer


You can search for integer association values



  field :budget, :integer do
    label 'Price in dollars'
    queryable true
    pretty_value do
      bindings[:object].budget.price_in_dollars
    end        
    searchable [{Budget => :price_in_dollars}]
  end

      

0


source







All Articles