steve hype steve hype - 1 year ago 109
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?

Answer Source

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 :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download