In my rails application, I use ransack to generate the sorts on the headers of my table.
This works on all columns that are included in my model, but I have a unit_price column that matches the below method of the Ingredient model which is actually a calculated field.
Is it possible to run a sort on the column header with a calculated field?
Is the only solution to save a unit_price field in the database?
def unit_price
self.price_cents / self.quantity_by_pack
end
I try this in my model, but doesn't work
ransacker :created_at do
Yes, it's possible
Firstly define ransacker and ransackable_attributes such way in your model
After that it's possible to apply it
or