ruby on rails country_options_for_select helper
So I’m still working away on this project using Ruby on Rails, and generally I’m loving it. It really is a great piece of software. Progress is good, but I often find myself stumbling on what should be the simple things.
Today for example, I wanted to use the country_options_for_select() form helper to generate a list of countries as a dropdown in a form, with a number of countries prioritised at the top of the list.
The list was being generated but the prioritised countries where not be generated. The code I had was something like this:country_options_for_select(priority_countries = ['United Kingdom','United States']).
Now the method signature in the api docs is this: country_options_for_select(selected = nil, priority_countries = nil), and I assumed that the selected = nil didn’t need to be included as it was the default.
Not so. Once I added the selected = nil argument to the method it worked.
And the lesson is?
Assumption is the mother of all feck ups I guess.