SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    0 Post(s)
    0 Thread(s)

    Simply Rails 2 - Counter Cache - please help!

    Hi all,

    I'm currently working through Simply Rails 2 and have come across a problem when trying to implement the Counter Cache in chapter 9.

    After following the counter cache instructions (which I've now gone through 3 times! and checked against the source code from SitePoint) I get this error when attempting to load the Stories page in Shovell

    ActiveRecord::StatementInvalid in StoriesController#index

    SQLite3::SQLException: no such column: votes_count: SELECT * FROM stories WHERE (votes_count >= 1) ORDER BY id DESC

    Could anyone give me some pointers as to where I might be going wrong? Obviously the column hasn't been created by my AddCounterCacheToStories migration file but I don't know why.

    When I run db:migrate AddCounterCacheToStories (which I *think* would only migrate this file - sorry newbie!) then I get the error "rake aborted! Don't know how to build task 'AddCounterCacheToStories'.

    The code in the file is;
    Code Ruby:
    class AddCounterCacheToStories < ActiveRecord::Migration
      def self.up
        add_column :stories, :votes_count, :integer, :default => 0
    	Story.find(:all).each do |s|
    	  s.update_attribute :votes_count, s.votes.length
      def self.down
        remove_column :stories, :votes_count
    Last edited by Mittineague; Jan 15, 2011 at 15:25. Reason: reformatting bbcode tags


Posting Permissions

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