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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:10:37+00:00 2026-05-27T01:10:37+00:00

Apologies in advance for the total beginner question, but since I am a beginner

  • 0

Apologies in advance for the total beginner question, but since I am a beginner here goes: In my Rails 3 app I have an attribute on my Profile model for :subject. In my form, I have the following code for the user to assign the :subject:

<%= f.select :profile_subject, options_for_select([['Select', 0], ['Arts', 1], ['Biology', 2], ['Business', 3], ['Chemistry', 4], ['English', 5], ['Foreign Language', 6], ['Government', 7], ['Health', 8], ['History', 9], ['Math', 10], ['Physics', 11], ['Vocational', 12]]) %>

I want to utilize the :subject strings for two things really:

  1. To render in my view
  2. To use in a search form (I’m using Ransack for the search)

I don’t think I set this up in my database (or built the form) properly, as I only appear to be storing the id (“ex: 1”) and not the string (“ex: Arts”). Before I remove the option id though, I’m curious: For something like this, is it considered good practice to include an option id as well as a string in the select? Or strip the id and just keep it as an array of strings only?

The reason for asking all this is regarding my search form. As I mentioned I’m using Ransack, and I’m just not sure how to make the f.select work with just a bunch of strings.

  • 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-27T01:10:37+00:00Added an answer on May 27, 2026 at 1:10 am

    First, I hadn’t set this up properly in my db. So I corrected the form so the :subject stored was a string. Here’s the new form:

    <%= f.select :subject, options_for_select([['Select', ''], ['Arts'], ['Biology'], ['Business'], ['Chemistry'], ['English'], ['Foreign Language'], ['Government'], ['Health'], ['History'], ['Math'], ['Physics'], ['Vocational']], :selected => @profile.subject) %>
    

    Then for the search form I just had to add a predicate _eq:

    <%= f.select :profile_subject_eq, options_for_select([['Select', ''], ['Arts'], ['Biology'], ['Business'], ['Chemistry'], ['English'], ['Foreign Language'], ['Government'], ['Health'], ['History'], ['Math'], ['Physics'], ['Vocational']], :selected => :profile_subject) %>
    

    And now it works.

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

Sidebar

Related Questions

This is a very wide-ranging/vague question, but here goes. Apologies in advance. The app
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Total newbie question here; I apologize in advance. Suppose I have a daemon written
Apologies in advance if this is a silly question, am very much a beginner.
Apologies in advance but I have never seen this error before and don't know
Apologies in advance for a policy, rather than a programming question, but given the
Apologies in advance if this question is badly worded! I have a MySQL table
Apologies in advance for the length of this question! I have a data structure
Apologies in advance, because I suspect this may be a silly question. I have
Apologies in advance if this is a silly question but I'm wondering which might

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.