Hi, I’m attempting to loop through an array in a method in a model,
Product.rb, and return a value if a certain conditional is met. I’m
having some trouble however, as it doesn’t seem to be working as
expected.
The method from my model is as follows:
def product_availability_label
QCC.config(:product_availability).each do |av|
“#{av.first}” if av.last == self.availability
end
end
The product availability array is declared elsewhere as:
config :product_availability, [[‘Immediate’,1],[‘1 Week’,2],[‘2
Weeks’,3],[‘3 Weeks’,4],[‘1 Month’,5]]
Returning a .type on QCC.config(:product_availability) from within
Product.rb confirms it’s an array and is the array I’m expecting,
however the output from the product_availability_label method is
“Immediate11 Week22 Weeks33 Weeks41 Month5”, rather than the expected
“Immediate” (in the instance where self.availability is 1). No errors
are raised.
I know I could do this from within a helper, but before I make any
alterations, I’d rather understand what’s going on. I’m using Ruby
1.8.5, Rails 1.1.6 on OSX should it make any difference.
Thanks