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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:13:37+00:00 2026-06-14T19:13:37+00:00

I’m using simple_form and i have a select menu with 3 values, which get

  • 0

I’m using simple_form and i have a select menu with 3 values, which get printed to the index. I want to know the correct and best way to get the value that the users sets, and then do a count of how many of the 3 different choices there currently are.

I’m new to ruby so this is a big learning curve and any help will be appreciated.

In my _form.html.erb

<%= f.input :menu, :as => :select, :collection => [ "Chocolate", "Cake", "Custard"] %>

My Index.html.erb

<td><%= reply.menu %></td>

db

class CreateReplies < ActiveRecord::Migration
  def change
    create_table :replies do |t|
      t.string :name
      t.integer :menu
      t.boolean :rsvp, :default => false

      t.timestamps
    end
  end
end
  • 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-14T19:13:38+00:00Added an answer on June 14, 2026 at 7:13 pm
    1. You’re looking to do a many-to-one relationship (many replies to one menu)
    2. Change your migration to be t.integer :menu_id
    3. Create another model called Menu with and id and i.e. name.

    So roll with something like the following:

    #  == Schema Information
    #
    #  Table name: replies
    #
    #  id          :integer          not null, primary key
    #  menu_id     :integer
    #  ...
    #  created_at  :datetime         not null
    #  updated_at  :datetime         not null
    
    
    class Reply < ActiveRecord::Base
      attr_accessible :menu_id, etc.
      belongs_to :menu, :inverse_of => :replies # belongs_to because has the FK 
     ...
    end
    
    #  == Schema Information
    #  
    #  Table name: menus
    #
    #  id         :integer          not null, primary key
    #  name       :string(255)
    #  created_at :datetime         not null
    #  updated_at :datetime         not null
    
    
    class Menu < ActiveRecord::Base
      attr_accessible :name
      has_many :replies, :inverse_of => :menu, :dependent => :nullify # the FK is in the reply
      accepts_nested_attributes_for :replies
    end
    

    And then since you’re using SimpleForm:

     <%= f.association :menu, :collection => Menu.all, :prompt => "- Select -"%>
    

    Then everything else is for the most part automated for you (i.e. when you create/update a reply it’ll grab the posted menu_id and assign it accordingly.

    If I were you, I’d dig into http://ruby.railstutorial.org/. It’s an excellent resource.

    Update: forgot about your view display (if you’re trying to display the name of the menu you selected – if you’re trying to display an entire menu, that’s a whole other different scenario):

    <td><%= @reply.menu.name %></td>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I'm trying to select an H1 element which is the second-child in its group
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.