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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:10:16+00:00 2026-05-27T14:10:16+00:00

I made a relationship with the three models using has_many :through : class Curriculum

  • 0

I made a relationship with the three models using has_many :through:

class Curriculum class < ActiveRecord::Base

    has_many :interests
    has_many :vacancies,: through => :interests
end

class Vacancy class < ActiveRecord::Base

   has_many :interests
   has_many :resumes,: through => :interests
end

class Interest < ActiveRecord:: Base

    belongs_to :vacancy
    belongs_to :curriculum
end

And to create curriculum and vacancy, I create them by administrative, i need to know how can i create the interest to the id of the vacancy, and how it will be logged on the system I have to get the id of it and make the relationship in creating a new bank interest. I wonder how I can program it to do so, and I wonder how the controller will get the create action, and what better way to do this.

  • 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-27T14:10:16+00:00Added an answer on May 27, 2026 at 2:10 pm

    First, try to read the whole “Guide to Rails on Associations”, especially the part about has_many :through. Then check your schema if your db is migrated and contains for the table interests the necessary foreign keys to curriculums and vacancies called curriculum_id and vacancy_id.

    If that is all in place, the following code will create the relationship between two objects:

    @curr = Curriculum.find(1)
    @vac = Vacancy.find(1)
    @curr.interests << @vac
    @curr.save
    

    The last two lines creates an interest between @curr and @vac and store that on the database. So you should not use IDs and handle them directly, but work with objects instead.

    The second part now is to provide a UI to allow the definition (and removal) of interests between curricula and vacancies. The base flow here is:

    • You have one curriculum in focus.
    • You have a link to add / remove curricula.
    • The view that opens shows a list of possible vacancies, where every vacancy has a checkbox.
    • By selecting (or deselecting) the check boxes, the IDs of the vacancies will be held in the params of the request sent to the controller.

    See the (older) podcast Railscast #52 how to do that in a similar context. Or see the example for has_many :through with checkboxes.

    An alternative way would be to use JQuery autocomplete, and add so interests one-by-one. See the nice podcast Railscast #258 which uses JQuery Tokeninput for that.

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

Sidebar

Related Questions

I made a class from Linq to SQL Clasees with VS 2008 SP1 Framework
I made a class that derives from Component: public class MyComponent: System.ComponentModel.Component { }
Running Rails 3.0.7 on Mac OS X with Ruby 1.9.2 I have three models
I'm creating 3 lists using Sharepoint 2010 UI. The lists and relationship are as
There are a number of posts and threads on has_many :through, but I haven't
Say I have a model that looks like: class StockRequest(models.Model): amount_requested = models.PositiveIntegerField(null=True) amount_approved
How can I generate form fields for a has_many :through association that has additional
I've made some changes in the table structure and especially the relationships between tables
Made solution change: I am trying to display a html table of data.. In
Made this nice little loop for hiding and showing div's, works as a charm

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.