Behold, a before_filter
:
class ThingController < ApplicationController
before_filter :check_stuff, :if => proc {Rails.env.production?}
end
<
From Rails 5.2 onwards, the current accepted answer is no longer be valid, and passing a string to the conditional will fail.
DEPRECATION WARNING: Passing string to :if and :unless conditional options is deprecated and will be removed in Rails 5.2 without replacement.
Going forward, a proc is now the best way to add a conditional like in the original question:
class ThingController < ApplicationController
before_action :check_stuff, :if => proc {Rails.env.production?}
end