I'm using Ransack's sort_link in my rails project to display a list of fees for my payment model. However, 'fee_amount' isn't an attribute of the payment model, but instead a class method of the bill model (which belongs to payment). What I have currently is:
<%= sort_link @search, :bill_fee_amount, "Convenience Fee" %>
which should accesses the bill of the current payment and call the 'fee_amount' method on that bill, which does some calculations and returns a float. It's these floats that I'm hoping to search by.
Can this be done, or can I only sort by attributes of the model I'm dealing with?
You can't with ransack as it comes, but check this issue. It seems some people has made patches for this functionality, but I haven't tried them.
Ransack, internally, it's always using the model as defined in the database, and I couldn't make it use the temporary tables created by the scopes.
PD: reworked the comment as an answer as I always come back to this question :P
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With