1

Say I have a text "favorite video url" field in my app, I need a way to tell rails that this is a url and then get be able to get parameters from it,

for instance, if the user inputs http://www.youtube.com/watch?v=RV0-DgsDLhs

I want to be able to get the 'v'param and store it in a variable.

Please help

1

1 Answer 1

7
require 'uri'
require 'cgi'

uri = 'http://www.youtube.com/watch?v=RV0-DgsDLhs'

params = CGI::parse( URI::parse(uri).query )

puts params.inspect # => {"v"=>["RV0-DgsDLhs"]}
puts params['v'][0] # => RV0-DgsDLhs

Why some of this functionality is in URI and some of it is in CGI is beyond me, but there you have it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.