Nupur Somani Nupur Somani - 2 years ago 97
SQL Question

How to convert session value to string in Ruby on Rails?

I want to store the cart items in my table but when I store it using the following code:

@order.items=@cart.items OR @order.items = session[:cart]

it stores values like
. I want the item names to be stored. How is it possible?
The order is my table with items column.
Any help will be appreciated.

Answer Source


@cart.items.collect {|cart| cart.value_you_want_to_collect}

ActiveRecord returns an association not just the values, so where there are multiple values, you need to collect them individually.

If there are multiple items you want to join you can call .join after the final }

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download