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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:13:14+00:00 2026-05-20T20:13:14+00:00

Hi I’m pretty new with Ruby On Rails, and came across this problem. I

  • 0

Hi
I’m pretty new with Ruby On Rails, and came across this problem.

I have 4 tables, and 1 that has the three others connected to it.

  1. Sportcategories – name of each category
  2. Sports – Name of each sport
  3. Clubs – Name of each club
  4. Results,
    t.integer “sportcategory_id”
    t.integer “sport_id”
    t.integer “club_id”

I have managed to make a simple edit form with text_field for each field in results. But how can I get the names for the integers instead of the numbers?

<%= form_for(@result) do |f| %>
  #if...
  #..
  #end
  <div class="field">
    <%= f.label :sportcategory_id%><br />
    <%= f.text_field :sportcategory_id%>
  </div>
  <div class="field">
    <%= f.label :sport_id %><br />
    <%= f.text_field :sport_id %>
  </div>
  <div class="field">
    <%= f.label :club_id %><br />
    <%= f.text_field :club_id %>
  </div>
  <div class="field">
    <%= f.label :result %><br />
    <%= f.text_field :result %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

I have made it so that SportCat, Sports and clubs has many results and that results belongs to all of them.

This is my controller file for results with edit & update

  def edit
    @result = Price.find(params[:id])
  end

  def update
    @price = Price.find(params[:id])

    respond_to do |format|
      if @price.update_attributes(params[:price])
        format.html { redirect_to(@price, :notice => 'Price was successfully updated.') }
        format.xml { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml { render :xml => @price.errors, :status => :unprocessable_entity }
      end
    end

  end

And question two might be answered in question one, but I want to be able to choose from a drop-down list from all the available categories, sports and clubs with their actual name and then pass the right ID when I update it.

  • 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-20T20:13:15+00:00Added an answer on May 20, 2026 at 8:13 pm

    Check the Rails Form select helper

    http://api.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-select

    <%= form_for(@result) do |f| %>
      <div class="field">
        <%= f.label :sportcategory_id%><br />
        <%= f.select :sportcategory_id, @sportcategories.map {|s| [s.name, s.id]} %>
       </div>   
      <div class="field">
        <%= f.label :sport_id %><br />
        <%= f.select :sport_id, @sports.map {|s| [s.name, s.id]}  %>
     </div>
     <div class="field">
        <%= f.label :club_id %><br />
        <%= f.select :club_id, @clubs.map {|c| [c.name, c.id]}  %>
     </div>
     <div class="field">
        <%= f.label :result %><br />
        <%= f.text_field :result %>
     </div>
     <div class="actions">
        <%= f.submit %>
     </div>
    

    <% end %>

    Get @sportcategories, @sports, @clubs in your controller actions.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.