Question

I not total sure if this system is caching the data but it has some of the charcteristics of caching.

Basicly I was messing with rails 3.2.4 and the system started to not display some of the results. I think this is dew to the default scope I put into the code model but even so this should display all the results not 9 out of 10. However I would always be missing the new records that I created and any other records that I create after that record. I check my sqlite3 database to see if the data was place in there and also check all the connection information along with making sure caching is off. However I could get the data to show up if I changed the any model file or controller file and then saved it. Would not even change the code just the touch command would do the trick. I think it has something to do with scope but I can't be total sure. One solution I found is just to go back down to Rails 3.2.2. It seams to do the trick. But I still don't like felling like I just gave in with out figuring this out.

development.rb

  # Show full error reports and disable caching
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false 

house.rb

class House < ActiveRecord::Base
  attr_accessible :name

  default_scope :order => 'created_at DESC', :limit => 50
  validates_presence_of :name
  has_many :roomies
end

schema.rb

ActiveRecord::Schema.define(:version => 20120601204050) do
  create_table "houses", :force => true do |t|
    t.string   "name"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
  end
end

houses_controller.rb

class HousesController < ApplicationController
  def index
    @houses = House.all
  end

  def new
    @house = House.new
  end

  def show
    @house = House.find(params[:id])
  end

  def create
    @house = House.new(params[:house])

    if @house.save
      flash[:success] = "Your house has been created and is ready to have people added to it."
      redirect_to houses_path
    else
      flash[:error] = "Your house could not be added dew to a error!"
      render :action => :new
    end
  end
end

houses/index.html.erb

<%= debug @houses %>

As you can see nothing super crazy.

Was it helpful?

Solution

Rails 3.2.4 had a regression around unintentional caching of calls made to scopes. Try rails 3.2.5 instead, which includes this commit

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top