How do i get request.uri in model in Rails?

后端 未结 6 456
一生所求
一生所求 2021-02-01 07:00
$request = request

When I write this in controller, it will work. But if i need this variable in Model or Application controller, How can i ?

6条回答
  •  我在风中等你
    2021-02-01 07:34

    I got it

    class ApplicationController < ActionController::Base
      protect_from_forgery
    
      before_filter :beforeFilter
    
      def beforeFilter
         $request = request
      end  
    end
    

    Now we can use the $request global variable anywhere in the code

提交回复
热议问题