Question

I'm trying to capture the URL parameters from the following URL with Sinatra: http://localhost:4567/token#access_token=7nuf5lgupiya8fd6rz4yzkzvwwo2ria&scope=user_read

I'm tried using a couple code blocks to do this:

get '/token' do
    puts params['access_token']
end

and

get '/:token' do |token|
    puts token
end

and

get '/token#:token' do |token|
    puts token
end

However none of these work. In the first block I get an empty string, in the second block I get the string "token", and in the third block I get "Sinatra doesn't know this ditty".

What would be the appopriate solution in this example?

Was it helpful?

Solution

Is that url you wrote correct? I think it needs to be

http://localhost:4567/token?access_token=7nuf5lgupiya8fd6rz4yzkzvwwo2ria&scope=user_read

With a ? instead of a # after /token. With that change, you should be able to access all the query parameters in the params hash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top