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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:24:58+00:00 2026-06-17T08:24:58+00:00

I’m having some problems with ruby on rails, specifically setting up a many-to-many connection

  • 0

I’m having some problems with ruby on rails, specifically setting up a many-to-many connection with deal and event through deal_event. I’ve checked out several similar stackoverflow questions and even http://guides.rubyonrails.org/ but I’m still not getting something..

Here are my models:

deal.rb

class Deal < ActiveRecord::Base
  has_many :deal_events
  has_many :events, :through => "deal_events"
  attr_accessible :approved, :available, :cents_amount, :dollar_amount, :participants, :type
end

event.rb

class Event < ActiveRecord::Base
  has_many :deal_events
  has_many :deals, :through => "deal_events"
  attr_accessible :day, :image, :description, :location, :title, :venue, :remove_image
end

deal_event.rb

class DealEvent < ActiveRecord::Base
  belongs_to :deal
  belongs_to :event
end

And here are my migration files:

20130102150011_create_events.rb

class CreateEvents < ActiveRecord::Migration
  def change
    create_table :events do |t|
      t.string :title,     :null => false
      t.string :venue
      t.string :location
      t.text :description 
      t.date :day

      t.timestamps
    end
  end
end

20130112182824_create_deals.rb

class CreateDeals < ActiveRecord::Migration
  def change
    create_table :deals do |t|
      t.integer :dollar_amount
      t.integer :cents_amount
      t.integer :participants
      t.string  :type, :default => "Deal"
      t.integer :available
      t.string  :approved

      t.timestamps
    end
  end
end

20130114222309_create_deal_events.rb

class CreateDealEvents < ActiveRecord::Migration
  def change
    create_table :deal_events do |t|
      t.integer :deal_id, :null => false
      t.integer :event_id, :null => false

      t.timestamps
    end
  end
end

After I seed my database with one deal and one event, I go into the console and type in

deal = Deal.first # ok
event = Event.first # ok

DealEvent.create(:deal => deal, :event => event) # Error: ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: deal, event

deal.events # Error: ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the association "deal_events" in model Deal

Any idea on what I’m doing wrong for these two errors to be popping up? Thanks.

  • 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-17T08:25:00+00:00Added an answer on June 17, 2026 at 8:25 am

    You’ll need this line in your DealEvent model:

    attr_accessible :deal, :event
    

    Although if it’s just a relationship table (which it looks like) then you don’t create the relationship that way. Use nested forms and the like.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
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
For some reason, after submitting a string like this Jack’s Spindle from a text
Specifically, suppose I start with the string string =hello \'i am \' me And
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.