Get current action path / url including query string? (Rails)

A simple question: how do I get the path or full URL of the current action, INCLUDING the query string?

I want to save it in a session variable as follows:

def show
  @thingy = Thingy.find(params[:id])

  session[:some_var] = current_url

  ...
end

Right now I'm doing the following, but it seems a bit heavy (especially for specifying the query string parameters separately):

def show
  @thingy = Thingy.find(params[:id])

  session[:some_var] = thingy_path(@thingy, :q1 => params[:q1], :q2 => params[:q2])

  ...
end
+5
source share
2 answers

request.url - This is probably what you are looking for.

+12
source

access params, it will give you a request, as well as controllerand action. Using an object request, you can dig deeper if you want.

+1
source

All Articles