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

后端 未结 4 756
情深已故
情深已故 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:24

    You can get full url object using

    url = Rails.application.routes.recognize_path(request.env['PATH_INFO'])

    now you can get components as

    url[:controller]

    url[:action]

    By default you can also use params[:controller] and params[:action] respectively during request/response life cycle.

提交回复
热议问题