Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

$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 ?

like image 558
Sreeraj Avatar asked Jun 10 '11 13:06

Sreeraj


People also ask

What is the best way to get the current request URL in Rails?

You should use request. original_url to get the current URL.

What is a model in a Rails application?

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.


1 Answers

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.

like image 101
DGM Avatar answered Oct 05 '22 15:10

DGM