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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:59:26+00:00 2026-06-12T20:59:26+00:00

I have a has_many through relationship between Course and User. class Course < ActiveRecord::Base

  • 0

I have a has_many through relationship between Course and User.

class Course < ActiveRecord::Base
  belongs_to :user

  has_many :enrollments, :dependent => :delete_all
  has_many :users, :through => :enrollments

  attr_accessible :description, :duration, :name, :prerequisites, :short_name, :start_date, :user_id

  accepts_nested_attributes_for :users, :allow_destroy => true
  attr_accessible :users_attributes

and User:

class User < ActiveRecord::Base

has_many :subjects, :class_name => "Course"  # to get this call user.subjects
has_many :enrollments, :dependent => :delete_all
has_many :courses, :through => :enrollments

and Enrollment:

class Enrollment < ActiveRecord::Base

belongs_to :course
belongs_to :user

attr_accessible :course_id, :user_id

end

Now I’m trying to set user_ids from inside Course, using a nested form. It keeps giving me that Mass Assignment warning, and nothing is saved. I read I was supposed to add attr_accessible user_id but it still doesn’t work.

Even if I do something like this from the rails console:

@c.update_attributes({:user_ids => [7,8]})

with @c being the course

Any help would be greatly appreciated,
Thank you.

  • 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-12T20:59:28+00:00Added an answer on June 12, 2026 at 8:59 pm

    It’s user_ids, not user_id.

    You need to add user_ids to your attr_accessible.

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

Sidebar

Related Questions

I have a basic has_many through relationship: class Foo < ActiveRecord::Base has_many :bars, :dependent
I have a has_many :through relationship set up like so class Situation < ActiveRecord::Base
consider this code class User < ActiveRecord::Base has_many :views has_many :posts, :through => :views,
I have a many-to-many relationship between users and teams (as a has_many :through), and
Ok, so I have 2 models with a has_many :through relationship: class Server <
I have a many-to-many relationship like this: A user has_many organizations through affiliations and
noob question here. I have a has_many :through relationship between items and tags. Finding
Let's say I have a many-to-many relationship between users and group. A user can
I have a fairly standard 'has_many :x, :through => :y' relationship with a user,
I have the following models: school.rb class School < ActiveRecord::Base has_many :offers has_many :players,

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.