I'm saving a bunch of ID's to the session like this.
session[:id_group] = 1,2,3,4,5
Because I need to save them to a data base with a form.
In that form I have hidden-field :
<%= form.text_field :group, :value => session[:id_group].inspect%>
I use the inspect so that the value saved to the database gets to be [1,2,3,4,5] and not 12345
The problem is, when I get that value from the DB I get [1,2,3,4,5] as a String. If I do:
groups = game.group
=> [1,2,3,4,5]
group.class
=>string
I can convert it to an array like this:
groups = game.group.split(',')
but then if I do
groups.each |group| do
puts |group|.to_s
end
I get
[1
2
3
4
5]
And I need the clean ID's so I can do something like
but then if I do
groups.each |id| do
User.find_by_id(id)
end
How can I fix this mess? Thanks in advance.