0

Friends,

I have a simple query like this one:

ContactForm.where(:is_active => true).order(:name => :asc)

But I want one of my records to appear always first, so I prefixed it with a couple hyphens "--", however, the order clause is not swapping that record to the first place, in fact it's still in the middle, as it wouldn't have those hyphens.

What can be happening?

Thank you.

Kunstmann
  • 109
  • 1
  • 10
  • Have you tried defining a scope that sorts using a regex? Something like [this](http://stackoverflow.com/a/26587907/382982). – pdoherty926 Jan 26 '15 at 19:10

1 Answers1

2

I suggest you to create another column instead of using that approach. You can use a column named priority with 0 as default.

add_column :contact_form, :priority, :integer, default: 0

Then, you can use this code (assuming that you have flagged the priority record with 1 ):

ContactForm.where(:is_active => true).order(:priority, :name => :asc)
Rodrigo
  • 5,435
  • 5
  • 42
  • 78