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

  • Home
  • SEARCH
  • 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 9081759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:23:31+00:00 2026-06-16T20:23:31+00:00

When I access to the url like example.com/shop?genre=13, It should automatically show the default

  • 0

When I access to the url like example.com/shop?genre=13,
It should automatically show the default selection set with the value 13.
However, it shows very first line of selection.
Why?

 <%= select_tag :genre, options_for_select(Genre.all.map{ |g| [g.name, g.id] }),  :selected => params[:genre] %>
  • 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-16T20:23:34+00:00Added an answer on June 16, 2026 at 8:23 pm

    If you want to select an option, you need to pass the value to the options_for_select method. If you lookup the signature for the method you will find:

    options_for_select(container, selected = nil)
    

    Further reading of the docs at http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_for_select will lead you to the example:

    options_for_select(["Free", "Basic", "Advanced", "Super Platinum"], :selected => "Free", :disabled => "Super Platinum")
      <option value="Free" selected="selected">Free<%roption>\n<option value="Basic">Basic</ption>\n<option value="Advanced">Advanced<%roption>\n<option value="Super Platinum" disabled="disabled">Super Platinum</option>
    

    In your case you should be able to get it working with:

    <%= select_tag :genre, options_for_select(Genre.all.map{ |g| [g.name, g.id] },  :selected => params[:genre]) %>
    

    As a side note. I guess Genre is an ActiveRecord model. In this case you can use options_from_collection_for_select. This method is designed to create a list of options tags from an array of ActiveRecord models. You find the docs at: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-options_from_collection_for_select

    Your code could look something like:

    <%= select_tag :genre, options_from_collection_for_select(Genre.all, 'id', 'name', params[:genre]) %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My URL structure is like http://www.example.com/folder/index.php?dir=dir1 To be able to access it from http://www.example.com/folder/dir1
I would like to deny web robots to access a url like this: http://www.example.com/export
My URL structure is like http://www.example.com/folder/index.php?dir=dir1 To be able to access it from http://www.example.com/folder/dir1
I'm using codeigniter for a project. The URL is segmented like this: example.com/admin/events example.com/admin/events/add
I want to generate jsb3 files from a url like http://example.com/home . Its protected.
In a website I found, they use friendly URLs like this: Real URL: example.com/index.php?mode=product
i need to create an url like this: www.example.com/index.php/scheda/name-surname-id.html so i create the Scheda
I have an URL like this /home/action/id How can I access this id in
My URL currently looks like that http://www.mydomain.com/index.php?videoID=6nR9nsKTx4g but I want to access the page
I want to access the value of a specific variable (in the url) in

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.