Invalid argument for TimeZone?

I am trying to make my users the time zone of the current time zone of my application, so that everything they interact with will be just that. However, I came across ArgumentErrorfor my method inside my ApplicationController.

application_controller.rb

before_filter :set_user_time_zone

private

def set_user_time_zone
  if signed_in?
   Time.zone = Time.now.in_time_zone(current_user.time_zone)
  end
end

Notes: current_user is a Devise Helper and my user model as a column :time_zone.

Than the error:

invalid argument to TimeZone[]: Mon, 20 Aug 2012 13:16:20 JST +09:00

I don’t know where to go from here. Any ideas on how to fix this?

Thank.

UPDATE

class Price
  attr_accessible :date
  def self.today
    where(:date => Date.today)
  end
end

If my method is:

def set_user_time_zone
  if signed_in?
    Time.zone = current_user.time_zone
  end
end

The problem I have is this:

 Time.now = US EAST- 2012-08-22 21:17:03 -0400 
 Time.zone = TOKYO - (GMT+09:00) Tokyo 
 Time.zone.now 2012-08-23 10:17:03 +0900

This means that all my methods Dateare executed.

Time.now = US EAST- 2012-08-22 21:17:03 -0400

when should he be

Time.zone.now 2012-08-23 10:17:03 +0900

How can I get it last?

+5
source share
2

Time.now.in_time_zone(current_user.time_zone) TimeWithZone, Time#zone= -, TimeZone.

, TimeZone :time_zone ( " ( )", "" ..),

Time.zone = current_user.time_zone
+3

Time # zone = :

  • Rails TimeZone.

  • Rails TimeZone (, " " (US & ) ", -5 ).

  • TZInfo:: Timezone.

  • TZInfo:: Timezone (," /").

, -

+3

All Articles