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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:48:09+00:00 2026-06-17T23:48:09+00:00

Is it possible to somehow use the :selected option that you’d use on a

  • 0

Is it possible to somehow use the :selected option that you’d use on a normal select view helper with the grouped_collection_select function? I’d like to set the value that gets pre-selected in my list. I’ve tried passing in :selected as an option with no luck!

Here’s some code snippts of my tests:

grouped_collection_select 'user[subscription_attributes]', :subscription_plan_id, Trade.order(:name).all, :subscription_plans, :name, :id, :display_name, { :include_blank => true, :selected => 5 }

grouped_collection_select 'user[subscription_attributes]', :subscription_plan_id, Trade.order(:name).all, :subscription_plans, :name, :id, :display_name, :include_blank => true, :selected => 5 

Neither version works. No selected is set. I’m using this to set a value for a nested model. I’m using the railscasts dynamic select list methods: http://railscasts.com/episodes/88-dynamic-select-menus-revised

I couldn’t get formtastic to play nicely with the group selects so I had to do it by hand but I don’t keep this value selected when a user fails validations. I’d like to keep this set when they fix validation errors.

  • 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-06-17T23:48:10+00:00Added an answer on June 17, 2026 at 11:48 pm

    I just ran across the same problem and solved it using the option_groups_from_collection_for_select helper and the select helper documented at: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html.

    The first step is to create the grouped options. Taking your example, it should look like:

    <% options = option_groups_from_collection_for_select(Trade.order(:name).all,
       :subscription_plans, :name, :id, :display_name, 5) %>
    

    Then I created the select object like:

    <%= select('user[subscription_attributes]', :subscription_plan_id, options, 
      include_blank: true) %>
    

    You could write it all out in one line, I just broke out the options into a separate variable to illustrate the two different methods.

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

Sidebar

Related Questions

is it possible somehow to use the NOW() function or something similar in MYSQL
Is it somehow possible to use a MATCH pattern inside the ALL function (using
is it possible to somehow use function register_composite from psycopg2, when i am using
Is it possible to somehow use some of the PHP classes that come with
Is it possible somehow to define a constant that says what datatype to use
Is it somehow possible to use the 'With' keyword on an existing object? I
Is this possible somehow to generate a GUID in C#, that mostly corresponds to
Is it somehow possible to create something like a masterpage (asp.net) in jQuery Mobile?
Is it somehow possible, via CSS, to select labels which contains *: at the
Is it possible to somehow use a .bat file to script the schema and/or

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.