In your code, if session[:items]
is not present, you are assigning @value
(which is a Hash
) to it. So next time it will try to push items to Hash.
If you need an Array
for session[:items]
, this should work
if !session[:items].present?
session[:items] = [@value] # Here create an array with @value in it
else
session[:items].push(@value)
end
EDIT I see you have updated your question. So here is my updated answer
if !session[:items].present?
session[:items] = { 0 => @value }
else
session[:items][ session[:items].keys.max + 1 ] = @value
end