Radrails created a field for date <%= product.date_available.strftime("%y-%m-%d") %> What does this mean? Should the definition be date or datetime? I tried both and no results Jim -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060420/ed0cbb14/attachment.html
SIX-S wrote:> Radrails created a field for date > <%= product.date_available.strftime("%y-%m-%d") %> > What does this mean?That will convert the date "date_available" into a string with the format yy-mm-dd as described here: http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_time.html#Time.strftime> Should the definition be date or datetime? I tried both and no resultsNot quite sure what you''re asking here. Mark -- Posted via http://www.ruby-forum.com/.
Thanks for answering my question. I dont know where the name " "strftime" originates I described the date_available field in the table products(from tutorial "depot") as type datetime. I changed the table type of date_available as "date" when I had the error when running the program "list .rhtml" in my browser Firefox. JIm ----- Original Message ----- From: "Mark Paxton" <mark@paxton.plus.com> To: <rails@lists.rubyonrails.org> Sent: Thursday, April 20, 2006 4:55 PM Subject: [Rails] Re: checking date> SIX-S wrote: >> Radrails created a field for date >> <%= product.date_available.strftime("%y-%m-%d") %> >> What does this mean? > That will convert the date "date_available" into a string with the > format > yy-mm-dd as described here: > http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_c_time.html#Time.strftime > >> Should the definition be date or datetime? I tried both and no results > > Not quite sure what you''re asking here. > > Mark > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
SIX-S wrote:> Thanks for answering my question. > I dont know where the name " "strftime" originates > I described the date_available field in the table products(from tutorial > "depot") as type datetime. I changed the table type of date_available as > "date" when I had the error when running the program "list .rhtml" in my > browser Firefox. > JImWhat error do you have that you are trying to correct? datetime is the type stored in the database only, in your product object the attribute date_available will be of class Time... strftime is a method of Time. You may get an error when date_available is not set in a record you wish to display/list, it will complain that no such method nil.strftime exists. Try the line: <%= product.date_available.strftime("%y-%m-%d") unless product.date_available.nil? %> Or logic to that effect, alternatives can be found by searching the list archive. Cheers, Mark -- Posted via http://www.ruby-forum.com/.
I have a problem like the one described. My database has a a table paintings with a DATETIME field called creation_date. In list.rhtml I code: painting.creation_date.strftime("%y-%m-%d") Rails complains: You have a nil object when you didn''t expect it! The error occured while evaluating nil.strftime I''m sure the expression painting.creation_date results in a variable of class Time, as the expression painting.creation_date.class returns Time. So why does Rails think that painting.creation_date is a nil object?
He, I found out why Rails complains about nil.strftime: I have rows in my database with no value for the field creation_date. So, as a matter of fact, Rails doesn''t complain about errors in the code. While running the code Rails is checking (or reading) the database and finds nil values for the creation_date fields of some rows. That''s what is reported as nil.strftime
Anonymous wrote:> He, I found out why Rails complains about nil.strftime: > I have rows in my database with no value for the field creation_date. > So, as a matter of fact, Rails doesn''t complain about errors in the > code. While running the code Rails is checking (or reading) the database > and finds nil values for the creation_date fields of some rows. That''s > what is reported as nil.strftimeFor the record, Rails has a nifty little feature where if you create a table with a field named "created_on" it will automatically populate new rows with the current date. -- Posted via http://www.ruby-forum.com/.