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:
- To render in my view
- 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.
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:
Then for the search form I just had to add a predicate
_eq:And now it works.