title: Dynamically Load Model Data Using Jquery - Ruby on Rails
body: <hr>
  
  <p>I have some static data I load from my model into a select drop down in my view like this:</p>
  
  <pre><code>MONTHLY_LEVEL = [
    'Level_1', '1',
    'Level_2', '2',
    'Level_3', '3'
  ]
  </code></pre>
  
  <p>I'd like to load one of two sets of information for the drop down based based on the value of another drop down's selection.  So in my model, I'd add this:</p>
  
  <pre><code>ANNUAL_LEVEL = [
    'Annual_Level_1', '10',
    'Annual_Level_2', '20',
    'Annual_Level_3', '30'
  ]
  </code></pre>
  
  <p>Then I want to toggle what I load using jQuery like:</p>
  
  <pre><code>$("#model_interval").change(toggle_level);
  function toggle_level() {
      var interval = $("#model_interval").val();
      if (interval == 'monthly') {
         // load monthly_level
      } else if (interval == 'annual') {
         // load annual__level
      }
  }
  </code></pre>
  
  <p>I'm not sure how to do this.  My current select tag looks like this:</p>
  
  <pre><code>&lt;%= f.select :level, options_for_select(Model::MONTHLY_LEVEL, params[:level]), {}, :class =&gt; 'select' } %&gt;
  </code></pre>
  
  <p>I realize I'm using a helper method, and I'm not sure there is a way to write the options_for_select to pull down a different set of data from the model.  If necessary, I guess I can use a static select button and load a div, but I'd really like to keep the data in the model. Ideas?</p>