I have three attributes that I want to display on a page: length, height, and width.
If a fourth attribute (variable_dimensions) is set to true on the object (thus invalidating the need to enter data for the other attributes), I want to return a string that says "Dimensions variable." If width is nil, I want to return length x height. I want to return the full length x height x width otherwise.
I've attempted this as a helper.
module ItemsHelper
def dimensions_available(length, height, width)
if @item.variable_dimensions == true
return "Dimensions variable"
elseif width.nil?
dimensions = length, height
return dimensions
else
dimensions = length, height, width
return dimensions
end
end
end
This works when dimensions_variable is set to true. It does what I want with the objects that have variable dimensions. In the other two cases it's printing to the page as an array that looks like [60.3, 35.4, nil] when width is nil, and [39, 45.3, 30.4] otherwise. How do I remove the array styling so that it it looks like 10cm x 30cm x 48cm? I previously attempted this with string interpolation, but was told that it's an anti-pattern.