简体   繁体   中英

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 .

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

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

If it matters, I'm using Rails 4.0.10.

Try:

request.original_url 

This will get the absolute url. Documentation:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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