I have a list of values (Beginner, Intermediate, Advanced, Fluent, Native) that I would like to:
Is there a way of implementing this list to address all or most of my needs?
You can put the definition of an array in /config/locales/some_language.yml
for example you could have the following in en.yml
en:
experience_levels:
1: Beginner
2: Intermediate
3: Advanced
4: Fluent
4: Native
To get the key value pairs into a helper, the following should work:
def experience_levels
I18n.t(:experience_levels).map { |key, value| [ value, key ] }
end
To use this in a select box,you would just put the following in your form_for
<%= f.select :experience_levels, experience_levels %>
If you are using form_tag instead you need the following:
<%= select_tag :experience_levels, options_for_select(experience_levels) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With