Hi, I wonder if someone did already improve the default rails-date-time-fields? I really don''t like those 5 drop-down-fields that are needed to pick date and time. I know some usability-ressources I agree with that say: let your user write the stuff the way they like and catch the error in the backend. So I am looking for a date-time-function that checks different ways of time-formating and returns them to the user... Thanks ~Tobias -- Weblog: http://flyingsparks.wwwfiles.de/
On 16.9.2005, at 23.00, Tobias Jordans wrote:> > > Hi, > > I wonder if someone did already improve the default rails-date-time- > fields? > > I really don''t like those 5 drop-down-fields that are needed to > pick date > and time. I know some usability-ressources I agree with that say: > let your > user write the stuff the way they like and catch the error in the > backend. > > So I am looking for a date-time-function that checks different ways of > time-formating and returns them to the user...See http://wiki.rubyonrails.com/rails/show/CalendarHelper and its reference to request preprocessor. //jarkko> > Thanks > ~Tobias > > > -- > Weblog: http://flyingsparks.wwwfiles.de/ > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Monday 19 September 2005 07:48, Jarkko Laine wrote:> On 16.9.2005, at 23.00, Tobias Jordans wrote:> > So I am looking for a date-time-function that checks different ways > > of time-formating and returns them to the user... > > See http://wiki.rubyonrails.com/rails/show/CalendarHelper and its > reference to request preprocessor.The request preprocessor was a misbegotten idea, in my own humble opinion as its author. What I''m currently doing is add a class variable for the date format to ActiveRecord and overwrite write_attribute to use this as a format for strptime (see below). I''ve updated the CalendarHelper page. The functionality is mixed into AR::Base ActiveRecord::Base.class_eval do include BoilerPlate::Model::I18n end class ApplicationController < ... before_filter :localize ... def localize # determine locale and set other relevant stuff ActiveRecord::Base.date_format = date_format end end Michael require ''active_record'' require ''date'' module BoilerPlate # :nodoc: module Model # :nodoc: # I18n support for ActiveRecord. # Currently, all that it does is define a class variable # # ActiveRecord::Base.date_format # # and redefines +write_attribute+ to convert string values to dates # according to this format. module I18n def self.included(base) base.class_eval do unless method_defined?(:write_attribute_with_date_cast) alias_method :write_attribute_without_date_cast, :write_attribute def write_attribute_with_date_cast(attr, value) if column_for_attribute(attr).type == :date value = cast_to_date(value) end write_attribute_without_date_cast(attr, value) end alias_method :write_attribute, :write_attribute_with_date_cast cattr_accessor :date_format ActiveRecord::Base.date_format = ''%Y-%m-%d'' end end end protected def cast_to_date(value) case value when String Date.strptime(value, ActiveRecord::Base.date_format) rescue nil ### FIXME rescue better when Date, Time value else raise ArgumentError, "Argument for cast_to_date must be a String, Date, or Time; was: #{value.inspect}" end end end end end -- Michael Schuerig All good people read good books mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org Now your conscience is clear http://www.schuerig.de/michael/ --Tanita Tikaram, Twist In My Sobriety
Michael Schuerig <michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org> writes:> The request preprocessor was a misbegotten idea, in my own humble > opinion as its author. What I''m currently doing is add a class variable > for the date format to ActiveRecord and overwrite write_attribute to > use this as a format for strptime (see below). I''ve updated the > CalendarHelper page.I''m glad to hear this. I didn''t like the preprocessor either. I tried to use CalendarHelper without it with varying success. Actually, I couldn''t get the calendar helper to dump the right JS into the page so i''d work. I ended up hand coding the Calendar.setup function myself. :-( I''m sorry, I don''t remember what the problem was. I''m really glad to hear you''re still working with the CalendarHelper page though. I''ve got some stuff coming up this week that will be able to use it. I''ll take another look to see what the problem was/is or if it still exists. -- Doug Alcorn - http://lathi.net/RubyOnRailsDeveloper doug-jGAhs73c5XxeoWH0uzbU5w@public.gmane.org