I''m getting the following error when I run this line in the console:
History.find_ec_id(770893)
NameError: undefined local variable or method `target_history'' for
History:Class
I have the following methods in my History model. I don''t understand
why this doesn''t work. There is definitely a history with a route_id
of
40 and a so_number of 770893 in the db. Any ideas on what I''m doing
wrong here, or how I could do this better? Thanks!
def self.find_ec_history(so_number)
histories = History.find(:all, :conditions => [''so_number
?'',so_number], :order => ''timestamp desc'')
histories.each { |his|
if his.is_ec?
target_history = his
break
end
}
return target_history
end
def is_ec?
return route_id == 40
end
--
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
-~----------~----~----~----~------~----~------~--~---
jf wrote:> I''m getting the following error when I run this line in the console: > > History.find_ec_id(770893) > NameError: undefined local variable or method `target_history'' for > History:Class > > I have the following methods in my History model. I don''t understand > why this doesn''t work. There is definitely a history with a route_id of > 40 and a so_number of 770893 in the db. Any ideas on what I''m doing > wrong here, or how I could do this better? Thanks! > > def self.find_ec_history(so_number) > histories = History.find(:all, :conditions => [''so_number > ?'',so_number], :order => ''timestamp desc'') > > histories.each { |his| > if his.is_ec? > target_history = his > break > end > } > > return target_history > end > > def is_ec? > return route_id == 40 > end > >target_history is local to it''s original containing block. Define it ahead of time and you should be good to go. target_history = nil histories.each { |his| if his.is_ec? target_history = his break end } return target_history -- http://www.5valleys.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 -~----------~----~----~----~------~----~------~--~---
Whoops! I meant I ran the following in the console: History.find_ec_history(770893) -- 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''re right! Thanks so much 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-/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 -~----------~----~----~----~------~----~------~--~---