SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Stuck in Chapter 7 Getting no method error.

    All,
    Well it was bound to happen Im finally stuck.
    Chapter 7 Fig 7.10. Does not show up
    all I get is an error:

    NoMethodError in Story#show
    Showing story/show.rhtml where line #3 raised:
    undefined method `votes_count' for #<Story:0x126a218>
    Extracted source (around line #3):

    1: <h2>
    2: <span id="vote_score">
    3: Score: <%= @story.votes_count %>
    4: </span>
    5: <%= @story.name %>
    6: </h2>


    I've gone back over the coding and the documentation several times
    with no luck, Also I checked my tables have corresponding records
    for each other with good info (no null data)
    for whats it worth:
    Mac os X Leopard
    Ruby installed as recommended by the book
    Database is set to mysql (not sqllite3)

    Any ideas?
    sucks to be stuck!!!!!
    -=Sam

  2. #2
    SitePoint Member
    Join Date
    Jan 2008
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FIXED.....
    on Page 190 QUOTED
    "This is another method to which we gained access by defining the has_many rela-
    tionship. An alternative syntax that achieves the same result combines the name
    of an associated table (in this case, votes) with _count, like so:1
    >> s.votes_count
    => 1 " END QUOTED
    My experience was s.votes_count (DID NOT WORK FOR ME)
    however s.votes.count (DID)
    so I changed the entry show.rhtml from >>>
    <span id="vote_score">
    Score: <&#37;= @story.votes_count %>
    </span>
    TO >>>
    <span id="vote_score">
    Score: <%= @story.votes.count %>
    </span>

    Just in case this helps anyone.
    -=Sam

  3. #3
    SitePoint Zealot atetlaw's Avatar
    Join Date
    Feb 2007
    Location
    Melbourne, Australia
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This reply is late but there's a footnote on that page in the book:

    "This technique for counting records is in fact deprecated, meaning that it should no longer be used as it will cease to be available in future versions of Rails. However, I’ve included it here for a reason—
    we’ll be overriding this method with a database table column of the same name in Chapter 9, so we need to create it now."

    Thought I should include it on this thread for completeness.

    As SamRod has mentioned the *_count method has been deprecated in favour of *.count .

  4. #4
    SitePoint Wizard bronze trophy
    Join Date
    Oct 2001
    Location
    Vancouver BC Canada
    Posts
    2,033
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Hey Patrick (or Georgina), Maybe a note about this should be added to the corrections & errors page for the book.

    I got the book when it first came out and went through it with the version of Rails recommended in the book. Unfortunately I haven't had any production ROR work and started to forget everything I learned so the other day, I picked up the book again and started from scratch. I ran into this issue while working through the latest version of InstantRails.
    Andrew Wasson | www.lunadesign.org
    Principal / Internet Development

  5. #5
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that why it fails. until then (and may stay for good) your line 3 should be:
    3: Score: <%= @story.votes.size %>
    the votes_count is a new colomn in the stories db.


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
  •