
Hi Abhishek
You can try using Addressable gem for your requirement .
Step 1 : Install Addressable gem with the following command .
$sudo gem install addressable
Step 2 : Will be explaining with IRB u can try and integrate with
your rails application .
$ irb
> require 'rubygems'
> require 'addressable/uri'
> uri = Addressable::URI.parse("http://google.com")
=> #<Addressable::URI:0xfdb9aee5c URI:http://google.com>
Step 3 : You can extract only the host with the following command
> uri.host
=> "google.com"
There are many other different options which you can explore
http://addressable.rubyforge.org/api/classes/Addressable/URI.html
Hope this helps !
Best regards,
Srinivas Iyer
http://talkonsomething.com
http://twitter.com/srinivasiyermv
>
> irb(main):002:0> require 'addressable/uri'
> => true
> irb(main):003:0> uri =
> Addressable::URI.parse("http://www.usc.edu/home.html" )
> => #<Addressable::URI:0x90e89c URI:http://www.usc.edu/home.html>
> irb(main):004:0> uri.host
> => "www.usc.edu"
----
uri.host.split('.')[0]
Craig
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonra...@googlegroups.com
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---