Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 611805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:49:26+00:00 2026-05-13T17:49:26+00:00

I’m saving a bunch of ID’s to the session like this. session[:id_group] = 1,2,3,4,5

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T17:49:26+00:00Added an answer on May 13, 2026 at 5:49 pm

    You shouldn’t be encoding your values using inspect. That will get re-encoded into a literal string, which is probably not your intention.

    The correct way to put things in your form is to do the opposite of how you want to decode them:

    <%= form.text_field :group, :value => session[:id_group].join(',') %>
    

    Where join and split are matched up properly, it will work. The counterpart to inspect is eval and you really do not want to do that as someone can run arbitrary code that way.

    As a note, you can also load a bunch of users with a single query using something like:

    @ids = params[:group].split(/,/)
    
    @users = User.find_all_by_id(@ids)
    

    This is much more efficient than loading them in one at a time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I know there's a lot of other questions out there that deal with this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.