Behold, a before_filter
:
class ThingController < ApplicationController
before_filter :check_stuff, :if => proc {Rails.env.production?}
end
During a recent code review, I was asked, "Is the proc
is required for this to work?" The answer appears to be 'yes', but it's a reasonable question, and I had intended to answer it by referring to the Rails docs or guides or something on the use of conditionals with before_filter
(now an alias of before_action
).
I couldn't find any. The Action Controller Guide mentions :only
/:except
, but not :if
/:unless
.
Failing that, is there somewhere in the code I can point to that covers this? It's mentioned briefly here, but that's more about how :only
and :except
are handled, rather than :if
or :unless
.