获取当前操作的路径/ url包括查询字符串? (Rails) [英] Get current action's path/url including query string? (Rails)
本文介绍了获取当前操作的路径/ url包括查询字符串? (Rails)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
简单问题 - 如何获取当前操作的路径或完整网址包含查询字符串?
我希望将其保存到会话变量中, :
def show
@thingy = Thingy.find(params [:id])
session [:some_var] = current_url
...
end
$ b b
现在我正在做下面的事情,但似乎有点粗暴(特别是单独指定查询字符串参数):
def show
@thingy = Thingy.find(params [:id])
session [:some_var] = thingy_path(@thingy,:q1 => params [:q1],:q2 => params [:q2])
...
end
解决方案
request.url
可能是你要找的。 p>
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
解决方案
request.url
is probably what you are looking for.
这篇关于获取当前操作的路径/ url包括查询字符串? (Rails)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文