开发者

rails expire_action in observer?

Ugh. Not my day today.

I have an observer in our Rails 3.0x app

class EventObserver < ActionController::Caching::Sweeper
  observe :live_event, :event

  def after_update(event)
    Rails.logger.debug "EventObserver::after_update #{event.class.name}.#{event.id}"
    channels = Channel.being_used
    inc=channels.reject {|c| !c.current_source.events.include?(event) }
    inc.each do |c|
      expire_action("channel_tickers/#{c.id}.js")
      expire_action("channel_events/#{c.id}.js")
      Rails.logger.debug "expired stuff for channel #{c.id}"
    end
  end
end

I do an update of one of the watched classes and the after_update is开发者_StackOverflow社区 getting called, but it is not expiring anything. I see no calls to expire_action in the log.

I do see:

expired stuff for channel 63

So it is hitting that code and not bombing out.

I want to use an observer because these models are not updated from a controller but internally.


After some trolling around I found the answer. I added this line to the beginning of my 'after_update' method:

@controller ||= ActionController::Base.new # <= this line is the key! without this nothing works

You will get no exceptions, but without this it doesn't work. I guess somewhere down the line it is looking to see if @controller is present and if so do things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜