This plugin gives ActiveRecord the ability to do stricter date checking. Example: class Person < ActiveRecord::Base validates_date :date_of_birth end This will ensure that date_of_birth is a *valid* date. The date can be set initially as a string in any of the following formats: "2006-01-01" "1 Jan 06", or "1 Jan 2006" "1/1/06" # Day / Month / Year They will all be parsed into a date object before the model is saved. If the date has been set to an invalid string, eg "Meow", an error is added to the model. Example (using Person as defined above): p = Person.new p.date_of_birth = "1 Jan 2006" p.save # true p.date_of_birth = "java is better than ruby" p.save # false In the final example, as I''m sure you are aware, the record failed to save not only because "java is better than ruby" is an invalid date, but more importantly, because the statement is blatantly false. ;) Install with: script/plugin install http://svn.viney.net.nz/things/rails/plugins/validates_date Check it''s all working with: rake test:plugins [or rake test_plugins if you are using Rails 1.0] Suggestions, comments, problems are all welcome. -Jonathan. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/b82fc822/attachment.html
Does it check re days of the moth -- i.e. would 30 Feb throw an error? Chris T Jonathan Viney wrote:> This plugin gives ActiveRecord the ability to do stricter date > checking. Example: > > class Person < ActiveRecord::Base > validates_date :date_of_birth > end > > This will ensure that date_of_birth is a *valid* date. The date can be > set initially as a string in any of the following formats: > > "2006-01-01" > "1 Jan 06", or "1 Jan 2006" > "1/1/06" # Day / Month / Year > > They will all be parsed into a date object before the model is saved. > If the date has been set to an invalid string, eg "Meow", an error is > added to the model. Example (using Person as defined above): > > p = Person.new > p.date_of_birth = "1 Jan 2006" > p.save # true > > p.date_of_birth = "java is better than ruby" > p.save # false > > In the final example, as I''m sure you are aware, the record failed to > save not only because "java is better than ruby" is an invalid date, > but more importantly, because the statement is blatantly false. ;) > > Install with: > > script/plugin install > http://svn.viney.net.nz/things/rails/plugins/validates_date > <http://svn.viney.net.nz/things/rails/plugins/validates_date> > > Check it''s all working with: > > rake test:plugins [or rake test_plugins if you are using Rails 1.0] > > Suggestions, comments, problems are all welcome. > > -Jonathan. > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Yes it does.>> p = Person.find(:first) >> p.date_of_birth = ''30 feb 06'' >> p.save=> false>> p.date_of_birth = ''28 feb 06'' >> p.save=> true -Jonathan. On 3/10/06, ChrisT <chrismtaggart@gmail.com> wrote:> > Does it check re days of the moth -- i.e. would 30 Feb throw an error? > Chris T >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/08102fef/attachment.html
Does it take Ruby Date and/or Time objects in addition to strings? -- -- Tom Mornini On Mar 10, 2006, at 1:20 AM, Jonathan Viney wrote:> This plugin gives ActiveRecord the ability to do stricter date > checking. Example: > > class Person < ActiveRecord::Base > validates_date :date_of_birth > end > > This will ensure that date_of_birth is a *valid* date. The date can > be set initially as a string in any of the following formats: > > "2006-01-01" > "1 Jan 06", or "1 Jan 2006" > "1/1/06" # Day / Month / Year > > They will all be parsed into a date object before the model is > saved. If the date has been set to an invalid string, eg "Meow", an > error is added to the model. Example (using Person as defined above): > > p = Person.new > p.date_of_birth = "1 Jan 2006" > p.save # true > > p.date_of_birth = "java is better than ruby" > p.save # false > > In the final example, as I''m sure you are aware, the record failed > to save not only because "java is better than ruby" is an invalid > date, but more importantly, because the statement is blatantly > false. ;) > > Install with: > > script/plugin install http://svn.viney.net.nz/things/rails/plugins/ > validates_date > > Check it''s all working with: > > rake test:plugins [or rake test_plugins if you are using Rails 1.0] > > Suggestions, comments, problems are all welcome. > > -Jonathan. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/63f6fd3f/attachment.html
It works with Date objects, probably not Time though. It could be made to, but I wanted this for working with dates. I can possibly add an extra validator such as validates_datetime ... -Jonathan On 3/11/06, Tom Mornini <tmornini@infomania.com> wrote:> > Does it take Ruby Date and/or Time objects in addition to strings? > -- > -- Tom Mornini > >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060310/30bf61a0/attachment.html
I''ve just added a validates_time method in as well. Same principle as validates_date: class Person < ActiveRecord::Base validates_time :time_of_birth end p = Person.new p.time_of_birth = ''5am'' p.save # true p.time_of_birth = ''ceiling'' p.save # false Currently accepted formats are things like: 1am 12 30 3:30PM 7pm I''m using this in an application I''m developing at the moment, so there may be more additions coming if I need them. -Jonathan 6, Tom Mornini <tmornini@infomania.com> wrote:> > Does it take Ruby Date and/or Time objects in addition to strings? >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/69ec77eb/attachment.html
Hello New to programming and Ruby. I want to create an application that would be installed on a windows machine. It will hook to a unix server via ftp and display all the files on the server. It will also have an editing window to edit and create new documents and save them to the unix box all while the app is on the windows machine. A similar app is FTPEditor. Can I use Ruby to develop such an application. I would like for the app to be a very easy install and not insist that the user also have a webserver installed (apache) and what not. Thoughts ?
Perhaps you have the wrong idea about Rails. It''s a framework to create web applications with, not win32 applications. On 3/11/06, bkj123@gmail.com <bkj123@gmail.com> wrote:> > Hello > > New to programming and Ruby. I want to create an application that would > be installed on a windows machine. It will hook to a unix server via > ftp and display all the files on the server. It will also have an > editing window to edit and create new documents and save them to the > unix box all while the app is on the windows machine. A similar app is > FTPEditor. > > Can I use Ruby to develop such an application. I would like for the app > to be a very easy install and not insist that the user also have a > webserver installed (apache) and what not. Thoughts ? > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/51b0f359/attachment.html
It''s quite possible doing this with Rails. Basically you''ll need to develop web based ftp client and text editor. Thanks, Pratik
Jonathan Viney wrote:> This plugin gives ActiveRecord the ability to do stricter date checking. > Example: > > class Person < ActiveRecord::Base > validates_date :date_of_birth > endBrilliant, thanks a lot! Will come in very useful - perhaps should be integrated into core rails? Tom
Tom Taylor wrote:> Brilliant, thanks a lot! Will come in very useful - perhaps should be > integrated into core rails?That said - I''m getting a 404 on the file... Tom
Jonathan Viney
2006-Mar-11 15:06 UTC
[Rails] Re: [ANN] validates_date plugin for ActiveRecord
Ah, yes, I changed the name to validates_date_time when I added the time validation. script/plugin install http://svn.viney.net.nz/things/rails/plugins/validates_date_time The readme should tell you all you need to know. If you want to see the expected behaviour just have a look at the tests, should be pretty self-explanatory. -Jonathan. On 3/12/06, Tom Taylor <tom@tomtaylor.co.uk> wrote:> > Tom Taylor wrote: > > Brilliant, thanks a lot! Will come in very useful - perhaps should be > > integrated into core rails? > > That said - I''m getting a 404 on the file... > > Tom >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/e81cfddc/attachment-0001.html
Jeff Coleman
2006-Mar-11 16:13 UTC
[Rails] Re: Re: [ANN] validates_date plugin for ActiveRecord
Does it validate leap years? Jeff Coleman -- Posted via http://www.ruby-forum.com/.
Jonathan Viney
2006-Mar-11 21:32 UTC
[Rails] Re: Re: [ANN] validates_date plugin for ActiveRecord
You mean dates like 29 Feb 2004? Yes. Just install the plugin and have a play. -Jonathan. On 3/12/06, Jeff Coleman <progressions@gmail.com> wrote:> > > Does it validate leap years? > > Jeff Coleman-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060311/5cdbfa6a/attachment.html
Rath
2006-Mar-12 02:00 UTC
[Rails] Re: Re: Re: [ANN] validates_date plugin for ActiveRecord
Hi John, What about dates previous to 1970? Because at the moment I haven''t been able to validate dates before that year or do you know how can I do it? Matz mentioned it in another ruby forum that the dates need to be changed from Time to Date or the other way around... don''t remember but I don''t know how to implement that. Could you help he here. Thanks, Rafa Jonathan Viney wrote:> You mean dates like 29 Feb 2004? Yes. > > Just install the plugin and have a play. > > -Jonathan.-- Posted via http://www.ruby-forum.com/.
Jonathan Viney
2006-Mar-12 02:57 UTC
[Rails] Re: Re: Re: [ANN] validates_date plugin for ActiveRecord
Yes, validates_date will handle any dates that the Ruby Date class can handle, which includes dates back past 1970. -Jonathan. On 3/12/06, Rath <rathjunk@gmail.com> wrote:> > Hi John, > > What about dates previous to 1970? Because at the moment I haven''t been > able to validate dates before that year or do you know how can I do it? > Matz mentioned it in another ruby forum that the dates need to be > changed from Time to Date or the other way around... don''t remember but > I don''t know how to implement that. Could you help he here. > > Thanks, > > Rafa-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060312/615b8dcc/attachment.html
Jonathan Viney
2006-Mar-20 23:19 UTC
[Rails] Re: Re: Re: [ANN] validates_date plugin for ActiveRecord
I''ve just added the ability restrict the date to a given range. You can now do: class Person < ActiveRecord::Base validates_date :date_of_birth, :before => Proc.new { 1.day.from_now.to_date }, :after => Proc.new { Date.new(1900, 1, 1) } end The default behaviour has also changed to restrict the initial range to 1900 => 1 year from now. To override that pass :before => nil, or :after => nil. Grab it from http://svn.viney.net.nz/things/rails/plugins/validates_date_time if you''re interested. Cheers, Jonathan. On 3/12/06, Jonathan Viney <jonathan@bluewire.net.nz> wrote:> > Yes, validates_date will handle any dates that the Ruby Date class can > handle, which includes dates back past 1970. > > -Jonathan. >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060320/3aeead43/attachment.html
Stuart Rackham
2006-Mar-22 21:00 UTC
[Rails] Re: [ANN] validates_date plugin for ActiveRecord
On the same topic, here''s a date validator I posted to Code Snippets which accepts a wide range of user friendly date formats: http://www.bigbold.com/snippets/posts/show/1548 Cheers, Stuart Jonathan Viney wrote:> This plugin gives ActiveRecord the ability to do stricter date checking. > Example: > > class Person < ActiveRecord::Base > validates_date :date_of_birth > end > > This will ensure that date_of_birth is a *valid* date. The date can be > set > initially as a string in any of the following formats: > > "2006-01-01" > "1 Jan 06", or "1 Jan 2006" > "1/1/06" # Day / Month / Year > > They will all be parsed into a date object before the model is saved. If > the > date has been set to an invalid string, eg "Meow", an error is added to > the > model. Example (using Person as defined above): > > p = Person.new > p.date_of_birth = "1 Jan 2006" > p.save # true > > p.date_of_birth = "java is better than ruby" > p.save # false > > In the final example, as I''m sure you are aware, the record failed to > save > not only because "java is better than ruby" is an invalid date, but more > importantly, because the statement is blatantly false. ;) > > Install with: > > script/plugin install > http://svn.viney.net.nz/things/rails/plugins/validates_date > > > Check it''s all working with: > > rake test:plugins [or rake test_plugins if you are using Rails 1.0] > > Suggestions, comments, problems are all welcome. > > -Jonathan.-- Posted via http://www.ruby-forum.com/.
Hi: Validates_date is great! But I''m getting an error when using the "after" parameter: validates_date :birthdate, :message => ''is not a valid date'',:before => Proc.new {(Time.now - 10.years).to_date}, :after => Proc.new {(Time.now - 150.years).to_date}, :if => Proc.new{|profile| (profile.attributes_before_type_cast["birthdate"] && profile.attributes_before_type_cast["birthdate"] != "") } Gives this error: "invalid restriction" (eval):32:in `date_meets_relative_restrictions'' (eval):14:in `select'' (eval):14:in `date_meets_relative_restrictions'' (eval):31:in `validates_date'' Can you help? Mike -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
You are using an old version of the plugin. Try updating and let me know is that fixes your problem. -Jonathan. On Dec 22, 8:53 am, Mike Dershowitz <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hi: > > Validates_date is great! But I''m getting an error when using the > "after" parameter: > > validates_date :birthdate, :message => ''is not a valid date'',:before > => Proc.new {(Time.now - 10.years).to_date}, :after => Proc.new > {(Time.now - 150.years).to_date}, :if => Proc.new{|profile| > (profile.attributes_before_type_cast["birthdate"] && > profile.attributes_before_type_cast["birthdate"] != "") } > > Gives this error: > > "invalid restriction" > (eval):32:in `date_meets_relative_restrictions'' > (eval):14:in `select'' > (eval):14:in `date_meets_relative_restrictions'' > (eval):31:in `validates_date'' > > Can you help? > > Mike > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---