Hi. Hopefully you will see the code and see what I'm trying to do, and
see the problem. The loop seems messy, but my method to help with eye
strain is to match up the do-end's down an imaginary column... ie:
array.each # do # |i|
puts i # # <-imaginary column
# end #
##### So here's the code. ###########
def foo(argument1, argument2) #1
user = [2,5]
user.each do |bar|
output = [] #2
argument1.each do |i| #3
if i.parent.id == bar.id #4
output << i.parent.name
end
end
argument2.each do |i|
if i.parent.id == bar.id
output << i.name
end
end
return output
end
Comments:
#1 - argument comes in as arrays
#2 - let's setup the var that will return the array of collected data
#3 - i think this is where the problem may lie.
#4 - parent is an acts_as_tree method inside rails, just grabs the
parant.
notice how i call the iterating variable 'bar' inside this new
loop..is this legal?
My intuition tells me there's probably a better method to do this. Any
comments, suggestions would be appreciated.
Dominic
···
--
Posted via http://www.ruby-forum.com/.