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

后端 未结 6 378
一生所求
一生所求 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:10

    Models exist outside the context of a web request. You can instantiate them in irb, you can instantiate them in a delayed job, or a script, etc. If the model depended on the request object, none of these things would be possible.

    As tsdbrown says, you have to somehow pass in that information from the context that uses the model.

提交回复
热议问题