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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:15:20+00:00 2026-06-04T02:15:20+00:00

I’m trying to use the :through method for the first time in rails, doing

  • 0

I’m trying to use the :through method for the first time in rails, doing a rich many-to-many relationship exercise, and received an error at the command line when trying to test it out. Basically trying to point AdminUser to “sections” without going through “section_edits”.

Here is the console error

C:\Users\davo\Desktop\RailsProjects\simple_cms>rails c
Loading development environment (Rails 3.2.3)
irb(main):001:0> me = AdminUser.find(1)
  ←[1m←[36mAdminUser Load (1.0ms)←[0m  ←[1mSELECT `admin_users`.* FROM `admin_us
ers` WHERE `admin_users`.`id` = 1 LIMIT 1←[0m
=> #<AdminUser id: 1, first_name: "David", last_name: "Douglas", email: "", pass
word: nil, created_at: "2012-05-18 20:18:20", updated_at: "2012-05-18 20:18:20",
 username: "ddd1600">
irb(main):002:0> me.sections
ActiveRecord::HasManyThroughAssociationNotFoundError: Could not find the associa
tion "section_edits" in model AdminUser
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_r
ecord/reflection.rb:501:in `check_validity!'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/activerecord-3.2.3/lib/active_r
#etc, etc

Here are the three relevant classes:

AdminUser.rb

 class AdminUser < ActiveRecord::Base

  has_and_belongs_to_many :pages
  scope :named, lambda {|first,last| where(:first_name => first, :last_name => last)}

 has_many :section_edits
 has_many :sections, :through => "section_edits"
end

SectionEdit.rb

class SectionEdit < ActiveRecord::Base

  belongs_to :admin_user
  belongs_to :editor, :class_name => "AdminUser", :foreign_key => 'admin_user_id'

  belongs_to :section

end

Section.rb

class Section < ActiveRecord::Base

  belongs_to :page
  has_many :section_edits

  has_many :admin_users, :through => :section_edits
  has_many :editors, :through => :section_edits, :class_name => "AdminUser"

end

EDIT:
I have been able to do a (somewhat) inverse command to me.sections without a problem. Below, section points to AdminUser (editor).

irb(main):003:0> section = Section.find(1)
  ←[1m←[35mSection Load (0.0ms)←[0m  SELECT `sections`.* FROM `sections` WHERE `
sections`.`id` = 1 LIMIT 1
=> #<Section id: 1, page_id: nil, name: "Section One", position: 1, visible: fal
se, content_type: nil, content: nil, created_at: "2012-05-18 22:50:44", updated_
at: "2012-05-18 22:50:44">
irb(main):004:0> section.editors
  ←[1m←[36mAdminUser Load (209.0ms)←[0m  ←[1mSELECT `admin_users`.* FROM `admin_
users` INNER JOIN `section_edits` ON `admin_users`.`id` = `section_edits`.`admin
_user_id` WHERE `section_edits`.`section_id` = 1←[0m
=> [#<AdminUser id: 1, first_name: "David", last_name: "Douglas", email: "", pas
sword: nil, created_at: "2012-05-18 20:18:20", updated_at: "2012-05-18 20:18:20"
, username: "ddd1600">]
irb(main):005:0>
  • 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-04T02:15:23+00:00Added an answer on June 4, 2026 at 2:15 am

    Try changing:

     has_many :sections, :through => "section_edits"
    

    To:

     has_many :sections, :through => :section_edits
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
We're building an app, our first using Rails 3, and we're having to build
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I am trying to render a haml file in a javascript response like so:

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.