Navin Navin - 8 months ago 37
Ruby Question

rails each order with nil value

In rails application I want to sort task by priority, the priority have the value p1,p2,p3,nil. If I sort like this

task..order(:priority).each do |t|
puts t

The task which have nil as priority comes first, then other things are sorted based on order. I want task which have nil priority to go last on loop. How to accomplish this one?

I am using mysql db

Task.order('priority IS NULL, priority DESC')