SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: shovell

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

    Question shovell

    Hi,

    just finished Simply Rails 2, and can't get the counter_cache to work.
    Searched the forum but could not find anything.

    any newly created story is supposed to have :votes_count = 1 but i keep getting nil when i check in console and story doesn't come up on "Upcoming stories page". the code is identical with the book (or code archive)

    Any suggestions and help would be much appreciated.

    Thanks.

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,150
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Hi vvan, welcome to the forums.
    Chapter 9 has quite a bit to it. For example, the Vote model is changed to
    Code Ruby:
    class Vote < ActiveRecord::Base
      belongs_to :user
      belongs_to :story, :counter_cache => true
    end
    What page was the last one where everything was OK? All the unit and functional tests for chapter 8 passed? What page did you first notice a problem?

  3. #3
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Hi,

    Thanks for the reply but the problem was in the migration file to add the counter cache.

    There is a screencast at railscast for this, episode 23, it requires another line of code Story.reset_column_information just before Story.findall).each block.

    This fixed it all.

    Thanks again.


Tags for this Thread

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
  •