Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected timezone format with options_for_select and simple_form_for in Rails. #48

adrianmann opened this issue Feb 16, 2016 · 2 comments


Copy link

adrianmann commented Feb 16, 2016

I am using an tag to display a drop down of timezones. However, the format displayed is not what is expected. For example, instead of "Europe/Dublin", I am getting "Europe - Dublin"?

The following placed inside a simple_form_for block:

<%= f.label :timezone %>
<%= :timezone, options_for_select(TZInfo::Timezone.all.each) %>

returns timezones with the unexpected format, whereas a <select> tag displays them as expected.

How can I correct this issue so the format is returned in the expected way?

@adrianmann adrianmann changed the title Incorrect/unexpected timezone format. Unexpected timezone format with options_for_select and simple_form_for in Rails. Feb 16, 2016
Copy link

philr commented Feb 16, 2016

You are seeing the result of options_for_select calling TZInfo::Timezone#to_s on each Timezone.

TZInfo::Timezone.all_identifiers returns an array of identifiers and could be used instead of all:

<%= :timezone, options_for_select(TZInfo::Timezone.all_identifiers) %>

You could also call TZInfo::Timezone#identifier on each Timezone:

<%= :timezone, 
      options_from_collection_for_select(TZInfo::Timezone.all, :identifier, :identifier) %>

@philr philr added the question label Feb 16, 2016
@philr philr closed this as completed Feb 16, 2016
Copy link

adrianmann commented Feb 17, 2016

Thank you!

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

No branches or pull requests

2 participants