Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:47:48+00:00 2026-06-11T01:47:48+00:00

When I try: validates_inclusion_of :time_zone, :in => TimeZone validates_inclusion_of :time_zone, :in => Time.zone This

  • 0

When I try:

validates_inclusion_of :time_zone, :in => TimeZone
validates_inclusion_of :time_zone, :in => Time.zone

This error appears:

"<class:User>": uninitialized constant User::TimeZone (NameError)

I’m trying to let users select any time zone of the world but since I’m based in the U.S.A. my select menu is this:

<%= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones, {:prompt => "Select Your Time Zone *"}, {:id => "timezone"} %>

What’s the correct way to do this?

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:47:49+00:00Added an answer on June 11, 2026 at 1:47 am

    If you select the option with value "(GMT-05:00) Eastern Time (US & Canada)" this string is going to be passed to the model for validation. Your validates_inclusion_of is going to run Enum‘s .include? method on the collection you pass with :in.

    Neither Timezone and Time.zone extend Enum to my knowledge, so they will not return an Enum instance that .include? will return true/false for.

    If your select consists of ActiveSupport::TimeZone.us_zones, this is what you should be checking the inclusion validator against

    validates_inclusion_of :time_zone, :in => ActiveSupport::TimeZone.us_zones
    

    But as ActiveSupport::TimeZone.us_zones doesn’t return strings, one way you could get a common type for comparison is casting the above Enum‘s contents to strings.

    validates_inclusion_of :time_zone, :in => ActiveSupport::TimeZone.us_zones.map(&:to_s)
    

    With this, a selected value like "(GMT-05:00) Eastern Time (US & Canada)" should evaluate true, as the following does in console without trouble.

    > ActiveSupport::TimeZone.us_zones.map(&:to_s).include?("(GMT-05:00) Eastern Time (US & Canada)")
    => true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are getting following error when we try to validate our app. This bundle
Try this code - import java.io.StringReader; public class StringReaderTest { public static void main(String[]
Try this piece of code - public class WhitespaceTest { public static void main(String[]
why every time that i retrieve an existent User and try to update its
I have a user model like this: class User < ActiveRecord::Base validates :password, :presence
I get this erorr eerytime I try to create a user from the console.
I'm getting this error when I try to submit my form (/POSTS/SHOW): RuntimeError in
I'm using this to (try) to validate a 'strong' password in ColdFusion 7. if
This one really has me. I have this validation in my user model: validates
I know I can fix this issue with i18n, which I will try to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.