使用 Rails 3。我有以下内容:
# shop.rb
class Shop < ActiveRecord::Base
belongs_to :country, :touch => true, :counter_cache => :total_shops
...
end
# shops_controller.rb
class ShopsController < ApplicationController
def create
...
@shop.save
@new_total_shops = @country.total_shops
end
end
假设 initial@country.total_shops是2,那么当它创建时,它应该递增到3,但是当我abort(@country.total_shops)在该行之后尝试时@shop.save,它仍然显示2。当我刷新页面时,它显示3. 我想它只是更新有点慢。
如何快速获取最新值?
谢谢。