SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page 192 v.story not working

    Hi everyone,

    Working through the book - so far so good up until this annoyance...

    On page 192 in the console where you type:

    v = Vote.find(:first) followed by
    v.story

    I get this error on v.story ( below )

    All that has happened so far in Chapter 7 is creating the vote table ( done and OK ) and added 'has_many :votes' in story.rb &
    'belongs_to :story' in vote.rb, so not much to go wrong !!!!

    Any thoughts welcome !
    Dave

    >> v.story
    NoMethodError: undefined method `story' for #<Vote:0x47a6b0c>
    from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/base.rb:1860:in `method_miss
    ing'
    from (irb):17
    >> belongs_to :story
    NoMethodError: undefined method `belongs_to' for #<Object:0x294f9ec>
    from (irb):18
    Last edited by mattymcg; May 1, 2007 at 21:48.

  2. #2
    SitePoint Zealot daveporter's Avatar
    Join Date
    Mar 2002
    Location
    Perth, Western Australia
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    All OK now !!!
    Not sure why, but I went through all the console command again and now it is happy - me too
    Dave

  3. #3
    Team SitePoint Lucas Chan's Avatar
    Join Date
    Sep 2002
    Location
    Melbourne
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting. I was going through the Ruby book over the weekend and had exactly the same problem.

    I don't know too much about how Ruby handles changes to or additions to class files. I wonder if it caches them somehow?

    I tried these console commands again just now and it worked perfectly. Hrm....

  4. #4
    SitePoint Addict
    Join Date
    Jan 2006
    Posts
    268
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rails loads the class files every time the console starts, so if you change files, you need to restart the console to update the loaded files.

    hope that helps,
    cheers
    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 Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't have to restart the console: use "reload!".

  6. #6
    Team SitePoint Lucas Chan's Avatar
    Join Date
    Sep 2002
    Location
    Melbourne
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nice one. Thanks for the tip. I'm sure one of the Ruby experts here in the office could have told me that, my stubbornness gets the better of me sometimes.

    I'll have a chat to the tech editor and suggest that we add a note about this in the book.

    Once again you guys prove that our forums are a gold mine of information.


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
  •