Skip to content

Instantly share code, notes, and snippets.

@StaverDmitry
Created December 27, 2016 16:19
Show Gist options
  • Save StaverDmitry/2f9cfe7068cf208d4a0baa802634bcf5 to your computer and use it in GitHub Desktop.
Save StaverDmitry/2f9cfe7068cf208d4a0baa802634bcf5 to your computer and use it in GitHub Desktop.
def sorted_pax_list
ship_priority = ['Standard', 'Ensuite', 'Premier', 'Premier Plus']
name_condition = "CASE WHEN first_name <> '' THEN 1 ELSE 0 END DESC"
deck_condition = "CASE deck WHEN 'Above Deck' THEN 1 ELSE 0 END DESC"
ship_condition = "CASE ship_type "
ship_priority.each_with_index { |ship, i| ship_condition += "WHEN '#{ship}' then #{i} "}
ship_condition += "END DESC"
partners = Partner.where(id: enquiry.partners.pluck(:id)) # Somehow ordering does not work without this
partners.order("#{name_condition}, #{ship_condition}, #{deck_condition}")
end
@StaverDmitry
Copy link
Author

Таск: сортировка списка пассажиров( они же pax, они же partners ).
В приоритете наличие имени, во вторую очередь тип корабля, в последнюю очередь верхняя или нижняя палуба.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment