Reputation: 4032
I am trying to set cookie name dynamically in my rails application.
I am able to set cookie like this:
cookies[:users_id] = current_user.id
I want to set the cookie name dynamically. I tried like this and it's not working:
cookies[:'users_id_#{current_user.id}'] = current_user.id
How is it possible?
Upvotes: 0
Views: 544
Reputation: 51191
You can use string as well as symbol, and if you want to perform interpolation, you need to use double ticks ("
)
cookies["users_id_#{current_user.id}"] = current_user.id
Upvotes: 2