2

I have a Sinatra application with the following GET method that takes the URL passed in:

get  %r{/html/(.+)}  do 
  url = params[:captures] # stores url => http://www.example.com

  gethtml(url)
end

However, when gethtml(url) is called, it raises the error Sinatra no implicit conversion of Array into String.

gethtml accepts input such as http://example.com.

I know this is a data-type conversion issue and I tried calling to_s but it did not work.

Any help would be appreciated.

1 Answer 1

4

params[:captures] returns an array of strings, while get_html most likely accepts one URL as string.

Since you want to use the first group that matches as the URL:

get %r|/html/(.+)| do
  get_html params[:captures].first
end

This is consistent with the Route matching with Regular Expressions example in the Routes section of the README.

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.