mirror of
https://github.com/internetee/registry.git
synced 2025-07-23 03:06:14 +02:00
Merge pull request #859 from internetee/remove-lib-from-autoload-path
Remove `lib` folder from autoload path
This commit is contained in:
commit
2828f8ca72
14 changed files with 57 additions and 58 deletions
40
app/models/sorted_country.rb
Normal file
40
app/models/sorted_country.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
class SortedCountry
|
||||
class << self
|
||||
include ActionView::Helpers
|
||||
|
||||
def all_options(selected = nil)
|
||||
quick_options = options_for_select(quick_list, selected: selected)
|
||||
|
||||
# no double select
|
||||
selected = quick_list.map(&:second).include?(selected) ? '' : selected
|
||||
|
||||
all_options = options_for_select([['---', '---']] + all_sorted_truncated,
|
||||
selected: selected, disabled: ['---'])
|
||||
quick_options + all_options
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def quick_list
|
||||
@quick_list ||=
|
||||
[
|
||||
%w[Estonia' EE],
|
||||
%w[Finland FI],
|
||||
%w[Latvia LV],
|
||||
%w[Lithuania LT],
|
||||
['Russian Federation', 'RU'],
|
||||
%w[Sweden SE],
|
||||
['United States', 'US']
|
||||
]
|
||||
end
|
||||
|
||||
def all_sorted
|
||||
@all_sorted ||= Country.all.sort_by(&:name)
|
||||
end
|
||||
|
||||
def all_sorted_truncated
|
||||
@all_sorted_truncated ||=
|
||||
all_sorted.map { |country| [country.name.truncate(26), country.alpha2] }
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue