1

I wanna get full URL in my rails app when someone hit to get my app. like. someone hit the URL in browser.

http://localhost:3000/ so I can get this in rails app with the help of request.original_url, and this gives me the correct result.

but when someone hit URL like this http://localhost:3000/#log-25 so request.original_urlthis is not giving me exact url which hit exactly it only return http://localhost:3000/ but I need #log-25 this part also.

so how can I get whole URL exactly as hit on the browser please help me.

Rana. Amir
  • 187
  • 3
  • 15
  • 2
    Possible duplicate of [Get anchor part of URL in controller in Ruby on Rails](https://stackoverflow.com/questions/4108082/get-anchor-part-of-url-in-controller-in-ruby-on-rails) – zeitnot Feb 28 '19 at 16:36
  • @zeitnot so it means there is no solution to handle without js. but if I handle this scenario with js then the problem is I made a call again for my server and I think this is not a good approch. – Rana. Amir Feb 28 '19 at 17:47
  • Why do you care in the controller about the anchor? This sounds like a [xy problem](https://meta.stackexchange.com/a/66378) to me. What do you try to achieve? What do want to do with that information in the controller? – spickermann Feb 28 '19 at 17:52

1 Answers1

2

The # part is not actually sent through to the server, it's a fragment that's used for in-page navigation, among other things, and is only relevant to the browser.

If you need the whole thing, fragment included, you'll need some JavaScript code to encode and supply that through another channel besides the HTTP request where it's intentionally stripped.

tadman
  • 208,517
  • 23
  • 234
  • 262
  • so it means there is no solution to handle without js. but if I handle this scenario with js then the problem is I made a call again for my server and I think this is not a good approch. – Rana. Amir Feb 28 '19 at 17:47
  • It's what you're stuck with because the fragment isn't supposed to be seen by the server, it's expected to be client-side only. Unfortunately this is how the standard is, so unless you want to petition to change the standard and wait ten years for adoption then you're stuck with this. If you have any control over the URI, come up with a scheme that doesn't involve fragments as a way to get around this limitation. – tadman Feb 28 '19 at 17:54