Hi guys: This is driving me crazy. Can someone please point me in the right direction: I''m trying to get the last record from my table. Every time I do this, it tells me there is no method, other than id. theconditions = "criteria = ''"+t+"''" lastrec = Capture.last(:all, :conditions => theconditions) This table has a number of fields in it id, created_at, tid, text When I call lastrec.id, it works When I call lastrec.created_at it gives me (undefined method `created_at'' for nil:NilClass) Any ideas? Thanks for your help! -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Chris Kalaboukis wrote:> Hi guys: This is driving me crazy. Can someone please point me in the > right direction: > > When I call lastrec.id, it works > When I call lastrec.created_at it gives me (undefined method > `created_at'' for nil:NilClass) > > Any ideas? Thanks for your help!If you look in your database, what does this id match to? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Aldric Giacomoni wrote:> Chris Kalaboukis wrote: >> Hi guys: This is driving me crazy. Can someone please point me in the >> right direction: >> >> When I call lastrec.id, it works >> When I call lastrec.created_at it gives me (undefined method >> `created_at'' for nil:NilClass) >> >> Any ideas? Thanks for your help! > > If you look in your database, what does this id match to?There is a record there, with that ID. I just can''t seem to call it up with a last command... -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 March 2010 18:56, Chris Kalaboukis <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Hi guys: This is driving me crazy. Can someone please point me in the > right direction: > > I''m trying to get the last record from my table. Every time I do this, > it tells me there is no method, other than id. > > theconditions = "criteria = ''"+t+"''" > lastrec = Capture.last(:all, :conditions => theconditions) > > This table has a number of fields in it > id, created_at, tid, text > > When I call lastrec.id, it works > When I call lastrec.created_at it gives me (undefined method > `created_at'' for nil:NilClass)I feel sure you must be mistaken somehow. Are you saying that if you immediately follow the Capture.last line with id = lastrec.id created_at = lastrec.created_at then the first line passes but you get the nil error on the second? I will be surprised if that is the case (I am often surprised mind you). One thing to try is to run that code in the ruby console. Another is to use ruby-debug to break in after the Capture.last line and examine the data at that point. See the rails guide on debugging if you do not know about ruby-debug (http://guides.rubyonrails.org/) Colin> > Any ideas? Thanks for your help! > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 11, 2010, at 2:21 PM, Colin Law wrote:> On 11 March 2010 18:56, Chris Kalaboukis <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> Hi guys: This is driving me crazy. Can someone please point me in the >> right direction: >> >> I''m trying to get the last record from my table. Every time I do >> this, >> it tells me there is no method, other than id. >> >> theconditions = "criteria = ''"+t+"''" >> lastrec = Capture.last(:all, :conditions => theconditions) >> >> This table has a number of fields in it >> id, created_at, tid, text >> >> When I call lastrec.id, it works >> When I call lastrec.created_at it gives me (undefined method >> `created_at'' for nil:NilClass) > > I feel sure you must be mistaken somehow. Are you saying that if you > immediately follow the Capture.last line with > id = lastrec.id > created_at = lastrec.created_at > then the first line passes but you get the nil error on the second? I > will be surprised if that is the case (I am often surprised mind you). > > One thing to try is to run that code in the ruby console. > Another is to use ruby-debug to break in after the Capture.last line > and examine the data at that point. > See the rails guide on debugging if you do not know about ruby-debug > (http://guides.rubyonrails.org/) > > ColinHmm, does the id happen to be 4? ;-) try: irb> puts nil.id Last relative to what? If you mean: most recently created, try: lastrec = Capture.first(:conditions => [''criteria = ?'', t], :order => ''created_at DESC'') -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 March 2010 20:42, Rob Biedenharn <Rob-GBZH0y1GwQfnZcttdmLDtcI/UQi/AW5J@public.gmane.org> wrote:> On Mar 11, 2010, at 2:21 PM, Colin Law wrote: >> >> On 11 March 2010 18:56, Chris Kalaboukis <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >>> >>> Hi guys: This is driving me crazy. Can someone please point me in the >>> right direction: >>> >>> I''m trying to get the last record from my table. Every time I do this, >>> it tells me there is no method, other than id. >>> >>> theconditions = "criteria = ''"+t+"''" >>> lastrec = Capture.last(:all, :conditions => theconditions) >>> >>> This table has a number of fields in it >>> id, created_at, tid, text >>> >>> When I call lastrec.id, it works >>> When I call lastrec.created_at it gives me (undefined method >>> `created_at'' for nil:NilClass) >> >> I feel sure you must be mistaken somehow. Are you saying that if you >> immediately follow the Capture.last line with >> id = lastrec.id >> created_at = lastrec.created_at >> then the first line passes but you get the nil error on the second? I >> will be surprised if that is the case (I am often surprised mind you). >> >> One thing to try is to run that code in the ruby console. >> Another is to use ruby-debug to break in after the Capture.last line >> and examine the data at that point. >> See the rails guide on debugging if you do not know about ruby-debug >> (http://guides.rubyonrails.org/) >> >> Colin > > Hmm, does the id happen to be 4? ;-) > > try: > irb> puts nil.idI suspect you may well have hit the nail on the head, but why would accessing nil.id in the code not generate the ''Called id for nil'' error? It does for me. Colin> > Last relative to what? If you mean: most recently created, try: > > lastrec = Capture.first(:conditions => [''criteria = ?'', t], :order => > ''created_at DESC'') > > -Rob > > > Rob Biedenharn http://agileconsultingllc.com > Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org > > > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 11, 2010, at 4:15 PM, Colin Law wrote:>> Hmm, does the id happen to be 4? ;-) >> >> try: >> irb> puts nil.id > > I suspect you may well have hit the nail on the head, but why would > accessing nil.id in the code not generate the ''Called id for nil'' > error? It does for me. > > Colindevelopment mode versus something else? (I think the whiny NilClass is only for development) -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.