I’m trying to write a method that takes :only and :except as an options hash and do some work based on those values. Quickly my code is bloated.
I can’t find how Rails handles those options in let’s say controller before filters?
Both only and except can be a symbol or an array eg. :only => :show or :only => [:show, :destroy]
Suggestions?
Check out the
_normalize_callback_optionsmethod in abstract_controller/callbacks.rb (this is rails 3).Basically what it does is create a string containing code for conditions you wanna impose. After that you’ll just need to eval this code, like