SHARE
TWEET

Untitled

a guest Mar 31st, 2012 8 Never
  1. # This is obviously one of your helper files
  2.  
  3. YourApp.helpers do
  4.   # see lib/current_controller_and_action.rb for more on why this works
  5.   # (and also why this is kind of a kludge)
  6.   def current_controller_and_action
  7.     @current_controller_and_action ||= begin
  8.       act, clr = @_template.to_s.sub(%r!^/!, "").split("/").reverse
  9.       clr ||= "app"
  10.       [clr, act]
  11.     end
  12.   end
  13.  
  14.   def current_controller; current_controller_and_action[0]; end
  15.   def current_action;     current_controller_and_action[1]; end
  16. end
RAW Paste Data
Top