Simple question - how do I get the path or full URL of the current action INCLUDING the query string?
I wish to save it to the session variable like so:
def show
@thingy = Thingy.find(params[:id])
session[:some_var] = current_url
...
end
At the moment I'm doing the following, but it seems a bit heavy-handed (especially the specifying of query string params individually):
def show
@thingy = Thingy.find(params[:id])
session[:some_var] = thingy_path(@thingy, :q1 => params[:q1], :q2 => params[:q2])
...
end
What is the best way to get the current request URL in Rails? You should use request. original_url to get the current URL.
You can write request. url instead of request. request_uri . This combines the protocol (usually http://) with the host, and request_uri to give you the full address.
You should use request. original_url to get the current URL. For Rails 3: You can write "#{request.
access params
variable,it will give you query as well as controller
and action
.
By using request
object you can dig more deeper if you want.
request.url
is probably what you are looking for.
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