URI::InvalidURIError bad URI(is not URI?): using Tanker
That's a URI.parse exception, it means some url is incorrectly specified or generated. Are you sure you set up the config correctly? From the readme at https://github.com/kidpollo/tanker you need to do:
Initialization
If you’re using Rails, config/initializers/tanker.rb is a good place
for this:YourAppName::Application.config.index_tank_url = 'http://:xxxxxxxxx@xxxxx.api.indextank.com'
If you are not using rails you can put this somewhere before you load
your modelsTanker.configuration = {:url => 'http://:xxxxxxxxx@xxxxx.api.indextank.com' }
You would probably want to have fancier configuration depending on
your environment. Be sure to copy and paste the correct url provided
by the IndexTank Dashboard
If you've already done that, please double check the urls for typos.
Sinatra/Rack `ERROR URI::InvalidURIError: bad URI(is not URI?)` on redirect
In the line
redirect to('/show/#{URI.escape((result.keys).first)}')
you are using single quotes. This means that string interpolation isn’t performed, so the literal string /show/#{URI.escape((result.keys).first)}
is being used as the url and that is why it is failing.
In order for interpolation to work you need to use double quotes like this:
redirect to("/show/#{URI.escape((result.keys).first)}")
This will cause #{URI.escape((result.keys).first)}
to be replaced with the escaped movie name, which should be a valid url.
Note that in your first redirect you do use double quotes, so it works as expected:
redirect to("/search/#{URI.escape(params['search'])}")
Open URI - Invalid URI Error, encoding/escaping not affecting
Don't try to inject variables into URLs. If they contain characters that need to be encoded per the spec, they won't be by interpolation. Instead, take advantage of the right tools for the job, like Ruby's URI class or the Addressable::URI gem.
See "How to post a URL containting curly braces and colons" for how to do this using well tested wheels.
In your situation, something like this will work:
require 'uri'
code = 'qwer3456*&^%'
start_month = 1
start_day = 1
start_year = 2014
end_month = 12
end_day = 31
end_year = 2015
uri = URI.parse("http://ichart.finance.yahoo.com/table.csv")
uri.query = URI.encode_www_form(
{
'g' => 'd',
'ignore' => '.csv',
's' => code,
'a' => start_month,
'b' => start_day,
'c' => start_year,
'd' => end_month,
'e' => end_day,
'f' => end_year
}
)
uri.to_s # => "http://ichart.finance.yahoo.com/table.csv?g=d&ignore=.csv&s=qwer3456*%26%5E%25&a=1&b=1&c=2014&d=12&e=31&f=2015"
URI.parse documentation
It seems URI(url)
and URI.parse(url)
do exactly the same:
u1 = URI("http://stackoverflow.com/")
u2 = URI.parse("http://stackoverflow.com/")
u1 == u2 # => true
Related Topics
How to 'Join' an Array Adding to the Beginning of the Resulting String the First Character to Join
404 Resource Not Found: Domain with Google Directory API
Initialize the Delayed Jobs Gem by Starting the Workers on Application Start
How to Implement Editing/Formating Text Area in Rails
Why Can't We Override '||' and '&&'
Rails Postgresql Multiple Schemas and the Same Table Name
Why Can't I Change the Value of Self
Rewrite Template.Js.Erb into Template.Js.Slim
Can Nokogiri Search for "Xml-Stylesheet" Tags
Why Capypara + Rspect Tests Still Pass Even Though I Delete Application.Js File
How to Split a String of Repeated Characters with Uneven Amounts? Ruby
Ruby Multiple Background Threads
Share Session Between Two Rails4 Applications
How to Run Rails App in a Completely Isolated Instances of Chrome
How to Get a List from a Ruby Enumerable
Ruby on Rails Workflow Engine (Like Ibm Workflow)
Rails Syntax Error: Unexpected Keyword_Ensure, Expecting Keyword_End