Hi All, I''m a bit stumped. All I''m trying to do is format a date and I get an error. Details below. I have a partial to list all "notes" associated with a "client" with the following code. <% for note in @client.notes %> <hr /> <%=h note.note_text %> Posted on <%=h note.created_at.strftime("%I:%M") %> by <%=h note.created_by %> <% end %> Which gives me the error... |"You have a nil object when you didn''t expect it! The error occured while evaluating nil.strftime" When I remove the |.strftime("%I:%M") from note.created_at the display works correctly showing the data with the default format of "Fri Feb 17 22:05:10 Central Standard Time 2006 by Sam Schroeder" I''m still fairly new to Rails so please bear with me. Thanks, Sam -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060218/fbf3ad72/attachment.html
On Fri, 2006-02-17 at 22:54 -0600, Sam Schroeder wrote:> Hi All, > > I''m a bit stumped. All I''m trying to do is format a date and I get an > error. Details below. > > I have a partial to list all "notes" associated with a "client" with > the following code. > > <% for note in @client.notes %> > <hr /> > <%=h note.note_text %> > Posted on <%=h note.created_at.strftime("%I:%M") %> by <%=h > note.created_by %> > <% end %> > > Which gives me the error... > > "You have a nil object when you didn''t expect it! The error occured > while evaluating nil.strftime" > > When I remove the .strftime("%I:%M") from note.created_at the display > works correctly showing the data with the default format of "Fri Feb > 17 22:05:10 Central Standard Time 2006 by Sam Schroeder" > > I''m still fairly new to Rails so please bear with me.---- is it possible that you have records in your table that don''t have this data? Did you create the records first, then add the ''created_at'' field later which might mean that you have records where this field is null? Craig
Craig White wrote:>On Fri, 2006-02-17 at 22:54 -0600, Sam Schroeder wrote: > > >>Hi All, >> >>I''m a bit stumped. All I''m trying to do is format a date and I get an >>error. Details below. >> >>I have a partial to list all "notes" associated with a "client" with >>the following code. >> >><% for note in @client.notes %> >><hr /> >><%=h note.note_text %> >>Posted on <%=h note.created_at.strftime("%I:%M") %> by <%=h >>note.created_by %> >><% end %> >> >>Which gives me the error... >> >>"You have a nil object when you didn''t expect it! The error occured >>while evaluating nil.strftime" >> >>When I remove the .strftime("%I:%M") from note.created_at the display >>works correctly showing the data with the default format of "Fri Feb >>17 22:05:10 Central Standard Time 2006 by Sam Schroeder" >> >>I''m still fairly new to Rails so please bear with me. >> >> >---- >is it possible that you have records in your table that don''t have this >data? Did you create the records first, then add the ''created_at'' field >later which might mean that you have records where this field is null? > >Craig > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >I did add the field in later but it does have the correct data it shows it as below without the formatting. "Fri Feb 17 22:05:10 Central Standard Time 2006 by Sam Schroeder" That is why I''m stumped at the error I get when attempting to format the data. Sam -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060218/f18a8e60/attachment.html
On Fri, 2006-02-17 at 22:54 -0600, Sam Schroeder wrote:> Hi All, > > I''m a bit stumped. All I''m trying to do is format a date and I get an > error. Details below. > > I have a partial to list all "notes" associated with a "client" with > the following code. > > <% for note in @client.notes %> > <hr /> > <%=h note.note_text %> > Posted on <%=h note.created_at.strftime("%I:%M") %> by <%=h > note.created_by %> > <% end %> > > Which gives me the error... > > "You have a nil object when you didn''t expect it! The error occured > while evaluating nil.strftime" > > When I remove the .strftime("%I:%M") from note.created_at the display > works correctly showing the data with the default format of "Fri Feb > 17 22:05:10 Central Standard Time 2006 by Sam Schroeder" > > I''m still fairly new to Rails so please bear with me.---- try removing the ''h'' <%= note.created_at.strftime("%I:%M") %> Craig
Craig White wrote:>On Fri, 2006-02-17 at 22:54 -0600, Sam Schroeder wrote: > > >>Hi All, >> >>I''m a bit stumped. All I''m trying to do is format a date and I get an >>error. Details below. >> >>I have a partial to list all "notes" associated with a "client" with >>the following code. >> >><% for note in @client.notes %> >><hr /> >><%=h note.note_text %> >>Posted on <%=h note.created_at.strftime("%I:%M") %> by <%=h >>note.created_by %> >><% end %> >> >>Which gives me the error... >> >>"You have a nil object when you didn''t expect it! The error occured >>while evaluating nil.strftime" >> >>When I remove the .strftime("%I:%M") from note.created_at the display >>works correctly showing the data with the default format of "Fri Feb >>17 22:05:10 Central Standard Time 2006 by Sam Schroeder" >> >>I''m still fairly new to Rails so please bear with me. >> >> >---- >try removing the ''h'' > ><%= note.created_at.strftime("%I:%M") %> > >Craig > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >Nope, same error. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060218/2d653aeb/attachment.html
Craig White wrote:> On Fri, 2006-02-17 at 22:54 -0600, Sam Schroeder wrote: >> <%=h note.note_text %> >> works correctly showing the data with the default format of "Fri Feb >> 17 22:05:10 Central Standard Time 2006 by Sam Schroeder" >> >> I''m still fairly new to Rails so please bear with me. > ---- > try removing the ''h'' > > <%= note.created_at.strftime("%I:%M") %> > > CraigI can''t seem to reproduce the error, using some test data the strftime you are using worked flawlessly. Perhaps try updating Rails to the latest version? If that doesn''t work I''m afraid I''m out of ideas. -- Posted via http://www.ruby-forum.com/.