0

With rails I can use this: request.original_url in order to get this: http://localhost:3000/

But if I click on a tab https://localhost:3000#tab1 how I can get the current full URL along with the tab??

Dev
  • 437
  • 6
  • 25
  • It's impossible not only with RoR but any other server side language. See more [here](https://stackoverflow.com/a/940923/1730761) – yeuem1vannam Apr 22 '19 at 08:46
  • Possible duplicate of [Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?](https://stackoverflow.com/questions/940905/can-i-read-the-hash-portion-of-the-url-on-my-server-side-application-php-ruby) – Eyeslandic Apr 22 '19 at 09:11

2 Answers2

4

You can't do it with Rails. Because the anchor is not sent to the server side.

In Rails you can only get URL with params.

But you can do it using JS: window.location

mechnicov
  • 12,025
  • 4
  • 33
  • 56
0

As others have mentioned, it's not possible simply because browsers will never send the hash property (it was originally used simply for jumping to different sections of the page).

Anyway, using hash in this way is a long-deprecated pattern. Instead, use the History API to change the path from JavaScript. Then the server will also be able to process such URLs. In Rails, there is the TurboLinks framework available to build your web app around this pattern.

mahemoff
  • 44,526
  • 36
  • 160
  • 222