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

纵饮孤独 提交于 2019-12-07 02:18:14

问题


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.



来源:https://stackoverflow.com/questions/12105472/get-current-actions-path-url-including-query-string-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!