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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:10:37+00:00 2026-05-24T22:10:37+00:00

I am brand new to Ruby, and have just now touched upon associations. Here

  • 0

I am brand new to Ruby, and have just now touched upon associations. Here are my models:

class Subject < ActiveRecord::Base

  has_many :pages

  scope :visible, where(:visible => true)
  scope :invisible, where(:visible => false)
  scope :search, lambda {|query| where(["name LIKE ?", "%#{query}%"])}
end

class Page < ActiveRecord::Base

  belongs_to :subject
  has_many :sections
  has_and_belongs_to_many :editors, :class_name => "AdminUser"

end

My tutorial (psh.. what does it know) told me to type “subject.pages”, after finding the first subject, like this:

Loading development environment (Rails 3.0.10)
irb(main):001:0> Subject.find(1)
=> #<Subject id: 1, name: "Initial Subject", position: 1, visible: true, created
_at: "2010-09-29 20:51:09", updated_at: "2010-09-29 21:07:42">
irb(main):002:0> subject.pages
NameError: undefined local variable or method `subject' for main:Object
        from (irb):2
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/comma
nds/console.rb:44:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/comma
nds/console.rb:8:in `start'
        from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.10/lib/rails/comma
nds.rb:23:in `<top (required)>'
        from script/rails:6:in `require'
        from script/rails:6:in `<main>'
irb(main):003:0>

According to the tutorial, it should have came back with an empty array. I have searched Google, this site, Yahoo Answers, everywhere for a possible explanation. Everything just seems to be correct to me. Can anyone help?

  • 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-24T22:10:39+00:00Added an answer on May 24, 2026 at 10:10 pm

    You need to store the result of Subject.find(1) into a variable before using it, just like you would with any language:

    subject = Subject.find(1)

    Then you can do subject.pages. Otherwise subject doesn’t refer to anything.

    Alternatively, you can use _ to refer to the return value of the last expression. So you could type Subject.find(1) and then _.pages.

    If you’re new to Ruby, though, I recommend going through this and perhaps this tutorial, and if you’re feeling brave, this guide.

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

Sidebar

Related Questions

I'm brand new to ruby and Watir, here's my issue... I have a MySQL
I'm a designer and brand new to programming. I have just opened my localhost
I just finished install Xcode, Homebrew, git, RVM and Ruby on a brand new
I'm brand new to ruby and rails and I'm having trouble creating a sign-out
I'm brand new to java, coming from a ruby world. One thing I love
Brand new to the Log4Net library and there is something I have not been
Brand new poster here on StackOverflow. I've been reading and learning here for some
It's a brand new project. Here's the exact commands I've run: rails new MyProject
I'm basically brand new to LINQ. I've looked around a lot on here and
I'm brand new to Ruby/Rails/RSpec, and hopefully this is a dumb/simple question. I'm currently

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.