0

I want to get anchor value from URL using ruby.

http://{My-Domain}/signin#recording

Want to get #recording value.

1 Answers1

3

You can use URI.parse to parse the URL, and then look for the attribute fragment:

require 'uri'

url = 'http://www.example.com/signin#recording'
uri = URI.parse url
uri.fragment
# => "recording"
Uri Agassi
  • 36,848
  • 14
  • 76
  • 93
  • How to get complete url in ruby because request.original_url give url without anchor. – Azhar Malik Dec 12 '14 at 09:38
  • that's because the browser does not pass the anchor to the server - see the comments under your question... – Uri Agassi Dec 12 '14 at 09:46
  • @UriAgassi so I was right about my comment ;) – Raj Dec 12 '14 at 10:07
  • @emaillenin - doesn't change the fact the it wasn't apparent from the question - it could easily ask about URLs coming from other places - exactly the reason the attribute `fragment` exists in the first place :-P – Uri Agassi Dec 12 '14 at 10:10
  • But my assumption was based on the tag [ruby-on-rails], but you could have been right as well :) – Raj Dec 12 '14 at 13:21