SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Problem with v.story in Chapter 7 of Book

    Hi,

    This topic was posted on a few months ago. It seems that others had the problem that I am having. However, no solution has been posted.

    I've created the Vote model:
    class Vote < ActiveRecord::Base
    belongs_to :story
    end

    which belongs to the Story model:
    class Story < ActiveRecord::Base
    validates_presence_of :name, :link
    has_many :votes
    end


    however in the Rails console, if I try to find the story for a vote entry, I get:
    >> v.story
    NoMethodError: undefined method `story' for #<Vote:0x2826730>
    from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/base.rb:1863:in `method_missing'
    from (irb):14
    from :0

    I've been following the book basically word-for-word and I can't figure out why I keep getting this error.

    Thanks in advance, Roseanne

  2. #2
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I fixed the problem. Here's my solution, in case anybody else has this problem.

    Roseanne
    ~/app/models/vote.rb
    class Vote < ActiveRecord::Base
    belongs_to :story,
    :class_name => "Story",
    :foreign_key => "story_id"
    end

  3. #3
    SitePoint Member
    Join Date
    Dec 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am currently working towards Chapter 7. An early thank you for posting about this.


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
  •