Rails - 获取不带 GET 参数的当前 url [英] Rails - Get the current url without the GET parameters

查看:65
本文介绍了Rails - 获取不带 GET 参数的当前 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

request.url 返回给我:http://localhost:3000/page?foo=bar.

request.url returns me this : http://localhost:3000/page?foo=bar.

有没有我可以调用的方法来获取 http://localhost:3000/page ,或者我可以必须解析字符串以去除获取参数?

Is there a method I can call to get http://localhost:3000/page , or do I have to parse the string to strip get parameters?

推荐答案

request.path 如果您不关心主机名,应该返回您要查找的内容.否则你可以试试:

request.path should return what you're looking for if you're not concerned about the hostname. Otherwise you might try:

url_for(:only_path => false, :overwrite_params=>nil)

这篇关于Rails - 获取不带 GET 参数的当前 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆