0

I have this error when I create a shift...

ActiveRecord::MultiparameterAssignmentErrors (2 error(s) on assignment of multiparameter attributes [error on assignment [8, 0, 1970, 1, 1] to inizio (undefined method `Europe/Rome' for Time:Class),error on assignment [16, 0, 1970, 1, 1] to fine (undefined method `Europe/Rome' for Time:Class)]):
  app/controllers/shifts_controller.rb:43:in `create'

In the application.rb i have

config.time_zone = 'Europe/Rome'
config.active_record.default_timezone = 'Europe/Rome'

the Model is

class Shift < ActiveRecord::Base

  after_initialize do
    self.stato ||= true
    self.inizio ||= Time.zone.now
    self.fine ||= Time.zone.now
  end

end

The Controller is : http://nopaste.info/3268dc795c.html

Migrate is : http://nopaste.info/eb674af117.html

SaroVin
  • 1,583
  • 3
  • 23
  • 46
  • 2
    Either duplicate of http://stackoverflow.com/questions/6118779/how-to-change-default-timezone-for-activerecord-in-rails3 or try "Rome" instead of "Europe/Rome". – lipanski Jan 20 '14 at 14:46
  • Do you have your application uploaded on Github or something? – Agis Jan 20 '14 at 15:00

2 Answers2

1

The issue is that active_record.default_timezone accepts only :local or :utc, so you must change settings in this way:

config.time_zone = 'Rome'
config.active_record.default_timezone = :local

Dopodiché ti suggerisco di scrivere sempre in inglese mentre programmi per avere coerenza all'interno del codice.
And by the way, I suggest you to always type in English when coding to improve consistency

View this GIST that show some details on why to use :local.
Watch also the second answer on this post, which is the correct one: https://stackoverflow.com/a/12127232/312907

And be careful, it's 'Rome', not 'Europe/Rome'

Community
  • 1
  • 1
Francesco Belladonna
  • 11,361
  • 12
  • 77
  • 147
0

For Europe/Rome rails has actually mapped it to just 'Rome' so you should be able to do this:

config.time_zone = 'Rome'
config.active_record.default_timezone = 'Rome'

You can find all the timezone mappings in the documentation for ActiveSupport::TimeZone

Aaron Miler
  • 869
  • 11
  • 22
  • I'd just add 'Europe/Rome' or equivalents for other capitals is just an identifier string for timezone information (`tzinfo` of `TZInfo::TimeZoneProxy` class). – David Unric Jan 20 '14 at 16:15