How to get request's target controller and action with Rails 3?

后端 未结 4 751
情深已故
情深已故 2021-02-01 01:35

In the application controller before filter.

class ApplicationController < ActionController::Base
  before_filter :authenticate

  def authenticate
    # How          


        
4条回答
  •  一整个雨季
    2021-02-01 02:21

    class ApplicationController < ActionController::Base
      before_filter :authenticate
    
      def authenticate
        # How do we know which controller and action was targetted?
        params[:controller]
        params[:action]
        # OR
        controller.controller_name
        controller.action_name    
      end
    end
    

提交回复
热议问题