$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 ?
You should use request. original_url to get the current URL.
A model is a Ruby class that is used to represent data. Additionally, models can interact with the application's database through a feature of Rails called Active Record.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With