I have the following function that will do a query for me, the problem I
am having (being new to Ruby and RoR) is how to reinitialize the object.
Right now it always returns the same value.
class AutoHarnesses < ActiveRecord::Base
end
def get_testruns(io)
agents = AutoHarnesses.new()
io.puts "What Agent''s test runs do you want to
see?\n"
io.print "Agent Name = "
my_agent = io.gets.chomp
io.puts "Looking for #{my_agent}\n"
begin
# I think this is the query I want....
agents = AutoHarnesses.first()
io.puts %{Found #{agents.testname} - #{agents.status}}
rescue
puts $!
end
end
I thought by having a new call at the beginning I could reinitialize the
object and clear it out so that I would always get a new one, or if
there was no result it would be empty when if did the Found statement.
Is there a way to assure that I am clearing out any earlier results from
the get_testruns function?
Thanks!
--
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
-~----------~----~----~----~------~----~------~--~---
On Apr 10, 3:43 pm, Michael Furmaniuk <rails-mailing-l...@andreas- s.net> wrote:> I have the following function that will do a query for me, the problem I > am having (being new to Ruby and RoR) is how to reinitialize the object. > Right now it always returns the same value. > > class AutoHarnesses < ActiveRecord::Base > end > > def get_testruns(io) > agents = AutoHarnesses.new() > io.puts "What Agent''s test runs do you want to see?\n" > io.print "Agent Name = " > my_agent = io.gets.chomp > io.puts "Looking for #{my_agent}\n" > begin > # I think this is the query I want.... > agents = AutoHarnesses.first() > io.puts %{Found #{agents.testname} - #{agents.status}} > rescue > puts $! > end > end > > I thought by having a new call at the beginning I could reinitialize the > object and clear it out so that I would always get a new one, or ifWell you do create a new instance of AutoHarnesses, but you then overwrite that with the result of AutoHarnesses.first which will always return the same thing. Frd> there was no result it would be empty when if did the Found statement. > Is there a way to assure that I am clearing out any earlier results from > the get_testruns function? > > Thanks! > -- > 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung wrote:> Well you do create a new instance of AutoHarnesses, but you then > overwrite that with the result of AutoHarnesses.first which will > always return the same thing. > > FrdOk...I had forgotten about first being like that. So if I have to look for just one machine what is the best option for select in this case? I''m just trying to keep it simple and I haven''t had much luck with using some of the select options as I keep getting undefined method errors. -- 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 -~----------~----~----~----~------~----~------~--~---
Sometimes a beer at lunch can help...still getting used to ActiveRecord
and its SQL format but this ended up working for me:
def get_testruns(io)
agents = AutoHarnesses.new()
# This gets the particular agent to search for
io.puts "What Agents test runs do you want to see?\n"
io.print "Agent Name = "
my_agent = io.gets.chomp
begin
# Look for agent by machine, get only the latest result
agents = AutoHarnesses.find_by_machinename(my_agent)
if agents.nil?
# The agent is not in the database
io.puts "We did not find any records matching your
request.\n"
else
io.puts %{Found #{agents.testname} - #{agents.status}}
end
rescue
# Print out errors in case of problems
puts $!
end
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
-~----------~----~----~----~------~----~------~--~---