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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:37:23+00:00 2026-05-13T08:37:23+00:00

I have table A with foreign key to table B in field b_id. Now

  • 0

I have table A with foreign key to table B in field b_id. Now I’m trying to make view/control for adding new table A entry. In form I have combo box (via collection_select) that lists all the elements from table B and that is where i intend to get the b_id for new instance of A in the create method for A.

Value of the combo box is set to the id of the desired B instance. But how do I set that value to the new A object’s b_id field in th ecreate method? What ever I try, it is always NULL and of course, I get the exception.

  • 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-13T08:37:24+00:00Added an answer on May 13, 2026 at 8:37 am

    I’m not sure I follow your question exactly, but it sounds like you may want to pass the ID directly from the params to the new A object’s create method… something like this:

    a = A.create( :b_id => params[:b_id], ... )
    

    It all really depends on what you’ve named the combo box in your view. If you could paste a snippet of your view then that would help


    Update based on comment.

    Looking at the rails docs for collection_select, it looks like you’re not passing the right data to collection_select

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

Sidebar

Related Questions

I have a table it includes 3 foreign key field like that: My Table:
I have a table with one field that can point to a foreign key
I have a table (session_comments) with the following fields structure: student_id (foreign key to
I have a table containing primary key and foreign key that references same table.
I have a table called TableA whch has a foreign key from TableB and
I have two tables with primary foreign key relationship. The table in foreign key
I have a User table which has a PrivilegeId foreign key points to a
I was making one table that have two foreign key to another tables. But
I have a bidding table, as follows: SellID INT FOREIGN KEY REFERENCES SellItem(SellID), CusID
Let's say I have a mysql table, called foo with a foreign key option_id

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.