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 3597974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:11:04+00:00 2026-05-18T20:11:04+00:00

(Using Rails 2.3.5 on an internal work server with no choice of versions, and

  • 0

(Using Rails 2.3.5 on an internal work server with no choice of versions, and I’m pretty new)

I’m building a search form where I need to provide a list of directories to a user so they can select which one(s) to search against. I’m trying to figure out how to get the selected values of a collection_select to remain after the form is submitted.

Say the user selected 3 directories from the collection_select, the id’s of those directories would look like this in the params:

directory: !map:HashWithIndifferentAccess 
  id: 
  - "2"
  - "4"
  - "6"

I know that you can manually specify multiple selected items:

<%= collection_select :directory, :id, @directories, :id, :name,
                 {:selected => [2,4,6]}, {:size => 5, :multiple => true} %>

I’ve also played around a bit and was able to us “to_i” against a single value in the params hash:

<%= collection_select :directory, :id, @directories, :id, :name,
                 {:selected => params[:directory][:id][0].to_i}, {:size => 5, :multiple => true} %>

What I can’t figure out is how to use all of the values of the :directory params at the same time so what the user selected remains after the form is submitted. Thanks for any help.

  • 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-18T20:11:05+00:00Added an answer on May 18, 2026 at 8:11 pm

    I’m not precisely sure what you’re asking, but if you’re trying to get the array of strings in params[:directory][:id] as an array of integers, all you need is

    params[:directory][:id].map{|id|id.to_i}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Using Rails 2.3.5 on an internal work server with no choice of versions, and
Rails 2.3.5 (internal work server - stuck at this version for inside apps) The
Using Rails 3.1.3 and Ruby 1.9.3. I want to give the user a list
I am using following versions of Ruby and Rails on arch linux [hardik@sunshine: kandibank
I have rails 3.1.3 and formtastic 2.0.2. I'm using the most basic form you
I have a Rails application and I'm using jQuery to query my search view
Building a rails B2B application that will have various users. I'm pretty clear on
So I am using Capistrano to deploy a rails application to my production server
I have a new-ish rails 3.1.1 app using sass/compass with compass taking care of
We have a rails server with custom 404 and 500 pages setup using this

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.