title: How to fix bad URI(is not URI?) in ruby on rails :URI::InvalidURIError
body: <p>I am unable to pass variables as parameters to this api: wounderground.</p>
  
  <p>I want to take inputs as city and state using input boxes and pass them as variables to the URI so that users can get their weather forecast.  However I am unable to pass variables as parameters to the api and am getting bad URI(is not URI?) or URI::InvalidURIError.  Can somebody please tell me how to fix it and tell me why I'm getting this error. if you need more information please let me know.  Thanks! </p>
  
  <p><strong>model: weathers.rb</strong>
      class Weathers</p>
  
  <pre><code>attr_accessor :temperature, :city, :state, :icon, :weekday_name, 
  :chance_of_rain, :chance_of_snow, :uvi, :tomorrow, :tomorrow_condition, 
  :tomorrow_icon, :day_one, `enter code here`:day_one_condition, 
  :day_one_high, :day_one_low, :day_two, :day_two_condition, 
  :day_two_high, :day_two_low
  
  def initialize(city, state)
  @city = city
  @state = state
  
  week_weather_hash = fetch_week_forecast(city, state)
  week_forecast(week_weather_hash)
  end
  
  def fetch_week_forecast(city, state)
  
  HTTParty.get("http://api.wunderground.com/api/apikey/forecast10day/q/#
  {city}/#{state}.json")
  end
  
  def week_forecast(week_weather_hash)
  weekly_forecast_response = 
  week_weather_hash.parsed_response['response']['forecast']
  self.day_one = weekly_forecast_response['txt_forecast']['forecastdays']
  ['forecastday'][0]['title']
  self.day_one_condition = weekly_forecast_response['txt_forecast']
  ['forecastdays']`enter code here`['forecastday'][0]['fcttext']
  
  self.day_one_high = weekly_forecast_response['simpleforecast']
  ['forecastdays']['forecastday'][0]['high']['fahrenheit']
  self.day_one_low = weekly_forecast_response['simpleforecast']
  ['forecastdays']['forecastday'][0]['low']['fahrenheit']
  
  self.day_two = weekly_forecast_response['txt_forecast']['forecastdays']
  ['forecastday'][2]['title']
  self.day_two_condition = weekly_forecast_response['txt_forecast']
  ['forecastdays']`enter code here`['forecastday'][2]['fcttext']
  
  self.day_two_high = weekly_forecast_response['simpleforecast']
  ['forecastdays']`enter code here`['forecastday'][1]['high']
  ['fahrenheit']
  self.day_two_low = weekly_forecast_response['simpleforecast']
  ['forecastdays']['forecastday'][1]['low']['fahrenheit']
  </code></pre>
  
  <p><strong>This is my controller:</strong>
      class ForecastsController &lt; ApplicationController<br>
      def show<br>
      @weather = Weathers.new(params[:city], params[:state])<br>
      end<br>
      end</p>
  
  <p><strong>show.html.erb</strong>
      
      Weekly forecast:
      
      <br>
      &lt;%=@weathers.day_one %> : &lt;%= @weathers.day_one_condition %> 
      <br>
      High/Low: &lt;%=@weathers.day_one_high %>F : &lt;%=@weathers.day_one_low %>F </p>
  
  <pre><code>&lt;br&gt;
  &lt;%=@weathers.day_two %&gt; : &lt;%= @weathers.day_two_condition %&gt;
  &lt;br&gt;
  High/Low: &lt;%=@weathers.day_two_high %&gt;F : &lt;%=@weathers.day_two_low 
  %&gt;F 
  </code></pre>
  
  <p>**my index.html.erb and new form ** </p>
  
  <pre><code>&lt;%= form_tag("/forecast", method: "get", class: "form-inline") do %&gt; 
  &lt;p class = "city-input"&gt;
  &lt;%= label_tag :City %&gt;
  &lt;%= text_field_tag :city,  nil, class: "form-control", placeholder: 
  "City Name" %&gt;
  &lt;/p&gt;
  
  &lt;p class= "state-input"&gt;
  &lt;%= label_tag :State %&gt;
  &lt;%= select_tag :state, options_for_select(us_states, "NY"), class: 
  "form-control" %&gt;
  &lt;/p&gt;
  
  &lt;p class= "submit"&gt;
  &lt;%= submit_tag 'Search', name: nil, class:"btn btn-primary" %&gt;
  &lt;/p&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>Below is the the full stack trace of the error</strong></p>
  
  <p>Started GET "/forecast?utf8=%E2%9C%93&amp;city=new+york&amp;state=NY" for 127.0.0.1 at 2017-10-26 20:09:14 -0400
     (0.2ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
  Processing by ForecastsController#show as HTML
    Parameters: {"utf8"=>"✓", "city"=>"new york", "state"=>"NY"}
  Completed 500 Internal Server Error in 10ms (ActiveRecord: 0.0ms)</p>
  
  <p>URI::InvalidURIError (bad URI(is not URI?): <a href="http://api.wunderground.com/api/apikey/forecast10day/q/new" rel="nofollow noreferrer">http://api.wunderground.com/api/apikey/forecast10day/q/new</a> york/NY.json):</p>
  
  <p>app/models/weathers.rb:15:in <code>fetch_week_forecast'
  app/models/weathers.rb:10:in</code>initialize'
  app/controllers/forecasts_controller.rb:36:in <code>new'
  app/controllers/forecasts_controller.rb:36:in</code>show'</p>
  
  <p><strong>Continuation of error</strong>
  bad URI(is not URI?): <a href="http://api.wunderground.com/api/apikey/forecast10day/q/new" rel="nofollow noreferrer">http://api.wunderground.com/api/apikey/forecast10day/q/new</a> york/NY.json</p>
  
  <p>Extracted source (around line #15):
  13
  14
  15
  16
  17
  18</p>
  
  <pre><code>def fetch_week_forecast(city, state)
      HTTParty.get("http://api.wunderground.com/api/apikey/forecast10day/q/#{city}/#{state}.json")
  end
  
  def week_forecast(week_weather_hash)
  </code></pre>