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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:03:56+00:00 2026-05-23T05:03:56+00:00

I want my users to be able to select from predefined values of categories.

  • 0

I want my users to be able to select from predefined values of categories. I took a look at other Stackoverflow questions but didn’t get them fully. Here is my code right now….

I have my Categories model and Users create prices (which is another name for Items).

class Category < ActiveRecord::Base
    has_many :prices

    def name
        "#{category}"
    end
end

My prices belong to categories. note: The prices table has a category_id.

class Price < ActiveRecord::Base
    attr_accessible :name, :date, :price

    belongs_to :user
    belongs_to :category
end

Here is how the form and view look as of now:

Form

<%= form_for(@price) do |f| %>
  <div class="field">
    <%= f.label :date %><br />
    <%= f.date_select :date %>
  </div>
  <div class="field">
    <%= f.label :name %><br />
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :price %><br />
    <%= f.text_field :price %>
  </div>
  <div class="field">
    <%= f.label :category %><br />
    <%= f.collection_select :category_id, Category.all, :id, :name, :prompt => true  %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

View

<p><b>User:</b><%= @price.user_id %></p>  
<p><b>Date:</b><%= @price.date %> </p>
<p><b>Name:</b><%= @price.price_name %></p>
<p><b>Price:</b><%= number_to_currency(@price.price) %></p>
<p><b>Category:</b><%= @price.category.name %></p>

How do i create the categories i want in the drop down menu?

Thank you I’m a very appreciative!

  • 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-23T05:03:56+00:00Added an answer on May 23, 2026 at 5:03 am

    You probably want the collection_select form helper method: http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select

    It will look something like this:

    <div class="category">
      <%= f.label :category %><br />
      <%= f.collection_select :category, Category.all, :id, :name %>
    </div>
    

    Then in the view:

    <p><b>Category:</b><%= @price.category.name %></p>
    

    This assumes that your categories table has a name field which stores the category names.

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

Sidebar

Related Questions

I want to be able to select the column from users and dusers. example:
I have a table of users that I want other users to be able
I want to select users from the users table based on: user.created user.sales_count So
I want the user to be able to select an option, which would change
Background: (Read before you flame...) I want a user to be able to SELECT
I want users to be able to upload files via FTP to my site
In my app I want users to be able to associate a file(s) they
Similar Stack Overflow Question I want users to be able to search through my
In my Rails app I want users to be able to input video links
I have an app where we want users to be able to send us

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.