tardjo
tardjo

Reputation: 1654

How to create a session that is an array in rails?

I want to fill session with many ids. How to create a session with many contents like an array?

example :

session[:store_id] = []
session[:store_id] << store.id

I get a result like this if I add many ids to my session :

 session[:store_id] << 1
 =>   result : [1]
 session[:store_id] << 2
 =>   result : [2]

I expect a result like this :

session[:store_id] = [1,2,3,4,5]

How do I do that?

Upvotes: 0

Views: 443

Answers (1)

Nitin Jain
Nitin Jain

Reputation: 3083

Try with session[:store_id] ||= []

Upvotes: 1

Related Questions