简体   繁体   English

Rails:如何编写当前页面的路径?

[英]Rails: How can I write a path to the current page?

How can I create a path that redirects back to the current page? 如何创建重定向回当前页面的路径?

Eg. 例如。 I'm on http://example/users/3 , I click on the link, and it redirects me to http://example/users/3 . 我在http://example/users/3 ,单击链接,它会将我重定向到http://example/users/3

This seems like it should be very simple, but I can't find anything online and all my guesses return an 'undefined method' error. 这似乎很简单,但是我无法在线找到任何东西,我的所有猜测都返回了“未定义的方法”错误。

I'm trying to print erb into an href link, so I think it has to be a path... something along the lines of 我正在尝试将erb打印到href链接中,所以我认为它必须是一条路径...类似

href="facebook/sharer/sharer.php?u=<%= path_to_current_url %>"

If it matters, I'm using Rails 4.0.10. 如果重要的话,我正在使用Rails 4.0.10。

Try: 尝试:

request.original_url 

This will get the absolute url. 这将获得绝对URL。 Documentation: 说明文件:

http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url http://api.rubyonrails.org/classes/ActionDispatch/Request.html#method-i-original_url

您可以使用request.env ['REQUEST_URI']将该URL作为字符串获取。

您可以使用<%= link_to "Refresh", '#' %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM