Question

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
Was it helpful?

Solution

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.

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