steve hype steve hype - 11 months ago 49
Ruby Question

Rails where query order by index of array

I'm trying to figure out a way I can order the following query by index in that array... => ["31f1d544-4ce5-4bcd-89fd-8a76e4c052fe",

@books = @books.where(" in (?)", if @books_sorted.any?


This should work.

@books_sorted.collect {|book| @books.detect{|x| ==}} if @books_sorted.any?

Please note: This isn't a efficient solution, since we are doing the sort in ruby instead of database query. Hope it helps :)