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

Closed
adrianmann opened this issue Feb 16, 2016 · 2 comments
Labels

Comments

@adrianmann
Copy link

@adrianmann adrianmann commented Feb 16, 2016

I am using an f.select 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 %>
<%= f.select :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
@philr
Copy link
Member

@philr 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:

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

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

<%= f.select :timezone, 
      options_from_collection_for_select(TZInfo::Timezone.all, :identifier, :identifier) %>
@philr philr added the question label Feb 16, 2016
@philr philr closed this Feb 16, 2016
@adrianmann
Copy link
Author

@adrianmann 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.