Wybo Wiersma
2006-Jan-30 10:38 UTC
[Rails] Introduction & time_zone_select with mapped TimeZone question
I''m new to this list, I''m a student in History, Computerscience and a bit of Philosophy from the Netherlands... I have started using rails a few weeks ago, I did read the Agile Webdevelopment with Rails book, and I generally started to love Rails for it''s sheer beauty and intelligent structure... However I came across something that puzzles me quite a bit. It''s how to add a time_zone_select form field using a composed_of class with mapped utc_offset and name fields... In my form I have: <%= time_zone_select(''user'',''time_zone'') %> In my user-class I have: composed_of :time_zone, :class_name => ''TimeZone'', :mapping => [%w(time_zone_name name) %w(time_zone_utc_offset utc_offset)] And I get this error: undefined local variable or method `utc_offset'' for User:Class I am using the stable version of Rails and User is part of the user_engine, but that should make no difference as I did overload the user-class (and other fields are working)... I tried a few alternatives to the time_zone_select vars (it''s not documented in the api exactly what arguments are requested...) like: <%= time_zone_select(''user.time_zone'',''time_zone_name'') %> <%= time_zone_select(''user.time_zone'',''time_zone_utc_offset'') %> But none of these work... It seems that it doesn''t get the mapping. While I think it is quite a common problem. I mean no one wants the ugly situation of a user.name field holding the name of a timezone, while almost all timezones are set using forms... I also had a look at the use of the TZInfo library, but it does seem likely that rails will one day support daylight savings times ?...and in that case it is wise to stick with rails...: http://lunchroom.lunchboxsoftware.com/pages/tzinfo_rails Wybo
Wybo Wiersma
2006-Jan-31 00:25 UTC
[Rails] time_zone_select with mapped TimeZone -> undefined local variable `utc_offset'' ? - Anyone ?
Am I missing something ? Or is it just a quirk that mappings don''t mix with time_zone_select ? Wybo> However I came across something that puzzles me quite a bit. It''s how to > add a time_zone_select form field using a composed_of class with mapped > utc_offset and name fields... > > In my form I have: > > <%= time_zone_select(''user'',''time_zone'') %> > > In my user-class I have: > > composed_of :time_zone, :class_name => ''TimeZone'', :mapping => > [%w(time_zone_name name) %w(time_zone_utc_offset utc_offset)] > > And I get this error: > > undefined local variable or method `utc_offset'' for User:Class > > I am using the stable version of Rails and User is part of the > user_engine, but that should make no difference as I did overload the > user-class (and other fields are working)... > > I tried a few alternatives to the time_zone_select vars (it''s not > documented in the api exactly what arguments are requested...) like: > <%= time_zone_select(''user.time_zone'',''time_zone_name'') %> > <%= time_zone_select(''user.time_zone'',''time_zone_utc_offset'') %> > > But none of these work... It seems that it doesn''t get the mapping. > > While I think it is quite a common problem. I mean no one wants the > ugly situation of a user.name field holding the name of a timezone, > while almost all timezones are set using forms... > > I also had a look at the use of the TZInfo library, but it does seem > likely that rails will one day support daylight savings times ?...and > in that case it is wise to stick with rails...: > http://lunchroom.lunchboxsoftware.com/pages/tzinfo_rails