Get current action's path/url including query

2019-04-26 23:25发布

问题:

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

回答1:

request.url is probably what you are looking for.



回答2:

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.