Get current action's path/url including query

2019-04-26 22:37发布

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

2条回答
Juvenile、少年°
2楼-- · 2019-04-26 23:30

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.

查看更多
Animai°情兽
3楼-- · 2019-04-26 23:35

request.url is probably what you are looking for.

查看更多
登录 后发表回答