SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ActiveRecord associations

    Hi,
    I am just going over a short Rails tutorial, and have hit a snag.
    When trying to create a belongs_to relationship, I am receiving an error "undefined method".

    The model in question is:
    Code:
    class Slide < ActiveRecord::Base
        belongs_to :slideshow
        belongs_to :photo
    end
    
    puts Slide.find(1).photo.filename
    That results in the error "undefined method 'photo'"

    What am I doing wrong?

    I had to manually download and intall the rails gems myself as I could not connect via the console.
    The following are the gems I have installed (gem list --local)
    actionmailer (1.2.5)
    actionpack (1.12.5)
    actionwebservice (1.1.6)
    activerecord (1.14.4)
    activesupport (1.3.1)
    rails (1.1.6)

    Maybe Im missing something?

    Any help is appreciated

    Thanks
    Mike

  2. #2
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    scratch that, I didnt realize I needed to restart the console for changes to take effect

  3. #3
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Instead of restarting console, just call the method reload!

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ooh, didn't know about that one! Thanks Luke
    If you give someone a program,
    you will frustrate them for a day;
    if you teach them how to program,
    you will frustrate them for a lifetime.

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah, thanks.
    I dont know why it occurred to me that the console was seeing the old version of the actual class file. That would have been a huge pain in the *** having to reload the console every time I changed the class file.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •