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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:48:22+00:00 2026-06-12T11:48:22+00:00

I have a ‘tip’ model and a ‘team’ model. I am trying to create

  • 0

I have a ‘tip’ model and a ‘team’ model. I am trying to create a form where a user will select the winning teams from several games. So far the user can select the winning teams and those id’s are being saved as foriegn keys in the Tip model (team_id). But after saving, I can’t go (for example ) @tip.team.name . What do I need to do ? How do I associate it (I though rails might magically do it if foriegn key is set), I am very new to rails. Thanks for any help !

class Tip < ActiveRecord::Base
attr_accessible :user_id, :team_id, :team, :game_id, :game, :comp, :comp_id
belongs_to   :game
belongs_to   :comp
belongs_to   :team
end

class Team < ActiveRecord::Base
attr_accessible :name
has_many   :tips
end

def create
params['game'][0].each do |key, value|
    @tip = Tip.new
    @tip.team_id = value
    @tip.game_id = key
    @tip.save
end

This last method may be messy too, but not sure how else to do it. There are several ‘tips’ that I want to create in the one form.

EDIT : To be clear I am quite sure it’s a one to many relationship, I am creating several tips in the one form but each tip only relates to one team.

EDIT : Actually my approach (which I’m sure is not close to the best way, did allow tip.team.name. It was a silly error relating to my test data that made me think otherwise.

  • 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-12T11:48:23+00:00Added an answer on June 12, 2026 at 11:48 am

    if ur asscociation is “Tip belongs to a Team ” and “Team can have many Tips” then the association u defined in the question is correct.

    if u want to created multiple tips when a team is created or add/edit/delete tips for a already created team, have a look at “accepts_nested_attributes_for” and https://github.com/ryanb/nested_form.

    If u can get the team name using ‘@team.name’ then u should get it using “@tip.team.name”

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

Sidebar

Related Questions

have a nice day. I got problem when trying to create an image from
I have a text area in my form which accepts all possible characters from
Have a painfully simple blog Post creator, and I'm trying to check if the
Have a SQL problem, adding this model all works correctly, the problem is in
Have a form here with bunch of input text fields and a file upload
Have such user_session model: class UserSession < Authlogic::Session::Base logout_on_timeout true # default if false
Have a simple form that has a PictureBox in one location. I want to
Have two tables say ABC and XYZ and contain one column which data will
have been trying couple of hours now to make my iphone app universal. The
Have one Doubt In MVC Architecture we can able to pass data from Controller

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.