So there's a bit of code that I want to execute on every request that is made to my rails application and found through googling that I can do it using before_filter. Buy it doesn't seem to run when I go to the initial page, which is localhost:3000. Anyone know why it doesn't run?

I'm using Ruby on Rails 3, WebBrick server on Lubuntu Linux.

class ApplicationController < ActionController::Base
  before_filter :run

  private
  def run
    logger.debug "run? I'm too tired"
  end
end
有帮助吗?

解决方案

If your initial page is a 'static' page served from the public directory this code will not be run. To fix, make the page render as the result of some controller's action that inherits from ApplicationController.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top