【发布时间】:2012-06-07 04:55:15
【问题描述】:
我不确定这个系统是否正在缓存数据,但它具有一些缓存特性。
基本上我在使用 rails 3.2.4 并且系统开始不显示某些结果。我认为这是我放入代码模型的默认范围的露水,但即使如此,这也应该显示所有结果,而不是 10 个中的 9 个。但是,我总是会丢失我创建的新记录以及我之后创建的任何其他记录那个记录。我检查我的 sqlite3 数据库以查看数据是否放置在其中,并检查所有连接信息以及确保缓存已关闭。但是,如果我更改任何模型文件或控制器文件然后保存它,我可以显示数据。甚至不会更改代码,只需触摸命令即可。我认为这与范围有关,但我不能完全确定。我发现的一种解决方案就是回到 Rails 3.2.2。它似乎可以解决问题。但我仍然不喜欢在没有弄清楚这一点的情况下就屈服了。
开发.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
房屋/index.html.erb
<%= debug @houses %>
正如你所见,没有什么超级疯狂的。
【问题讨论】:
标签: ruby-on-rails caching activerecord scope sqlite3-ruby