I have a collection of a model. I want to perform some complex sorting logic on this collection. The logic is not as simple as sorting based on a simple attribute. What the best way (performance and maintainability wise) to perform complex sorting logic on a collection of models. I am thinking along the lines of passing in a block to the sort method? But I am not sure…
Thanks.
Yes, you can use a block using
sort_bysort_byuses the Schwartzian transform internally in sort_by, so if your logic is a little more complex than that, you can still create a scoring function and pass it tosort_byAsk yourself if you can’t make the sorting directly from the SQL query, this will be a lot faster (assuming the right query and indices)