title: How to update a model's class method with form data
body: <p>This may be more of a conceptual issue than a syntactical one, but I would appreciate any input on how to approach the problem. I've been puzzling it over for the past couple of days, and have reached a wall.</p>
  
  <p>Here's a general overview of the situation, and I'll go into more specifics below.</p>
  
  <p>I want a user to be able to input his/her zip code, and then return the weather forecast based on that zipcode. </p>
  
  <p><strong>This is what I currently have:</strong></p>
  
  <p><strong>app/models/forecast.rb</strong> //
  gets weather data via HTTParty from external API, and formats XML response into the data that I want.</p>
  
  <pre><code>class Forecast &lt; ActiveRecord::Base
  
          attr_accessor :temperature, :icon
  
          def initialize
              weather_hash = fetch_forecast 
              weather_values(weather_hash)
          end
  
          def fetch_forecast
              HTTParty.get("http://api.wunderground.com/api/10cfa1d790a05aa4/hourly/q/19446.xml")
          end
  
          def weather_values(weather_hash)
              hourly_forecast_response = weather_hash.parsed_response['response']['hourly_forecast']['forecast'].first
              self.temperature = hourly_forecast_response['temp']['english']
              self.icon = hourly_forecast_response['icon_url']
          end
      end
  </code></pre>
  
  <p><strong>app/views/static_pages/home.html.erb</strong> // provides a form for zip code input at the top, and provides a place to display the information returned from the API at the bottom</p>
  
  <pre><code> &lt;div class="container"&gt;
          &lt;div class="row"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;div class="search-form"&gt;
  
                      &lt;%= form_tag("#", method: "get") do %&gt;
                        &lt;p&gt;&lt;%= label_tag(:zipcode, "Zipcode:") %&gt;&lt;/p&gt;
                        &lt;p&gt;&lt;%= text_field_tag(:zipcode, value = 19446) %&gt;&lt;/p&gt;
                        &lt;p&gt;&lt;%= submit_tag("Get Weather Forecast") %&gt;&lt;/p&gt;
                      &lt;% end %&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="row"&gt;
              &lt;div class="col-md-12 display"&gt;
                  &lt;div class="display-info"&gt;
  
                      &lt;h1&gt;Forecast Info&lt;/h1&gt;
                      &lt;%= @forecast.temperature %&gt;&lt;/p&gt;
  
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p><strong>My question is:</strong></p>
  
  <p>How do I connect the form data from the user to the model?</p>
  
  <p>My best guess is to build a form which instantiates a class of the model, calling the 'fetch_forecast' method with a url based on the user input, something along these lines:</p>
  
  <pre><code>def fetch_forecast(input)
      HTTParty.get("http://api.wunderground.com/api/10cfa1d790a05aa4/hourly/q/"+input+".xml")
  end
  </code></pre>
  
  <p>However, I have no idea whether this is correct or even possible, and if so, I have no idea how to go about doing this.</p>
  
  <p>Any suggestions or pointers more than welcome, and thank you for your help. </p>