Hello Everyone, in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following code: ------------------------------------------------------------------------------------------------------ class Date module Format # :nodoc: MONTHS = { ''january'' => 1, ''february'' => 2, ''march'' => 3, ''april'' => 4, ''may'' => 5, ''june'' => 6, ''july'' => 7, ''august'' => 8, ''september''=> 9, ''october'' =>10, ''november'' =>11, ''december'' =>12 } ------------------------------------------------------------------------------------------------------ How can I "overwrite" these values via my rails app? I''m trying to submit a foreign date to the database, so I want to overwrite (translate) this piece out of the format.rb file in my rails app, so that it understands which month I''m talking about. Any suggestions/tips how I can fix this in a smart/efficient way? Many Thanks in advance!
Maurício Linhares
2009-May-31 21:19 UTC
Re: Howto Overwrite existing Ruby Class via Rails app?
Look for Rails i18n helpers, they do what you''re looking for. - Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) On Sun, May 31, 2009 at 5:54 PM, Jermaine <Jermaine2028-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hello Everyone, > > in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following > code: > > ------------------------------------------------------------------------------------------------------ > class Date > > module Format # :nodoc: > > MONTHS = { > ''january'' => 1, ''february'' => 2, ''march'' => 3, ''april'' => > 4, > ''may'' => 5, ''june'' => 6, ''july'' => 7, ''august'' => > 8, > ''september''=> 9, ''october'' =>10, ''november'' =>11, ''december'' > =>12 > } > ------------------------------------------------------------------------------------------------------ > > How can I "overwrite" these values via my rails app? I''m trying to > submit a foreign date to the database, so I want to overwrite > (translate) this piece out of the format.rb file in my rails app, so > that it understands which month I''m talking about. > > Any suggestions/tips how I can fix this in a smart/efficient way? > > Many Thanks in advance! > > >
No that''s not the problem, in fact I''am using I18n. But that only works for translating /localizing your data from the database. But now I''m trying to Post data to the database. So for instance, if I would have a form with a text field: date_attended (<%f.text_field :date_attended%> and would post the following ''SPANISH'' date to the database: 10 Abril 2009 (-> which is April 10, 2009 in English) The database won''t understand this. So therefore I need to change this file: 1.8/usr/lib/ruby/1.8/date/ format.rb, because when I do that it works, but I want to do it via my rails app. I want to overwrite it there, but have no idea how. I was also thinking of maybe translating the months in the model itself, so that the database understands which month I''m talking about. But also I have no idea how to implement this in my code. I need (code)samples/ guidance, any suggestion is welcome. On May 31, 11:19 pm, Maurício Linhares <mauricio.linha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Look for Rails i18n helpers, they do what you''re looking for. > > - > Maurício Linhareshttp://alinhavado.wordpress.com/(pt-br) |http://blog.codevader.com/(en) > > On Sun, May 31, 2009 at 5:54 PM, Jermaine <Jermaine2...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hello Everyone, > > > in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following > > code: > > > --------------------------------------------------------------------------- --------------------------- > > class Date > > > module Format # :nodoc: > > > MONTHS = { > > ''january'' => 1, ''february'' => 2, ''march'' => 3, ''april'' => > > 4, > > ''may'' => 5, ''june'' => 6, ''july'' => 7, ''august'' => > > 8, > > ''september''=> 9, ''october'' =>10, ''november'' =>11, ''december'' > > =>12 > > } > > --------------------------------------------------------------------------- --------------------------- > > > How can I "overwrite" these values via my rails app? I''m trying to > > submit a foreign date to the database, so I want to overwrite > > (translate) this piece out of the format.rb file in my rails app, so > > that it understands which month I''m talking about. > > > Any suggestions/tips how I can fix this in a smart/efficient way? > > > Many Thanks in advance!
Erdwin Lianata
2009-Jun-01 01:48 UTC
Re: Howto Overwrite existing Ruby Class via Rails app?
create a new file under /lib directory ... i.e /lib/format.rb then overwrite from the file class Date module format MONTHS = { } # overwrite here end end overwriting a constant will result a warning! Jermaine wrote:> Hello Everyone, > > in the 1.8/usr/lib/ruby/1.8/date/format.rb file there is the following > code: > > ------------------------------------------------------------------------------------------------------ > class Date > > module Format # :nodoc: > > MONTHS = { > ''january'' => 1, ''february'' => 2, ''march'' => 3, ''april'' => > 4, > ''may'' => 5, ''june'' => 6, ''july'' => 7, ''august'' => > 8, > ''september''=> 9, ''october'' =>10, ''november'' =>11, ''december'' > =>12 > } > ------------------------------------------------------------------------------------------------------ > > How can I "overwrite" these values via my rails app? I''m trying to > submit a foreign date to the database, so I want to overwrite > (translate) this piece out of the format.rb file in my rails app, so > that it understands which month I''m talking about. > > Any suggestions/tips how I can fix this in a smart/efficient way? > > Many Thanks in advance!