title: Rails: How to add tooltip events in datepicker and limit them in few months
body: <p>I have a datepicker in which I want user to see coloured all the events created by admin. It would be nice to add the functionality to add a tooltip with the title of the event.</p>
  
  <p>I know that  <a href="http://jqueryui.com/demos/datepicker/" rel="nofollow">jQueryUI's datepicker</a> allows such a thing.
  I have to use the <a href="http://jqueryui.com/demos/datepicker/#event-beforeShowDay" rel="nofollow">beforeShowDay</a> method. But here comes the questions.</p>
  
  <p>1) How will I pass the @events array to the jquery code? I know I can access to that array in the view but am I allowed to do something like this: </p>
  
  <pre><code>var events = @events;
  </code></pre>
  
  <p>2) Second and <strong>most important question</strong>. This approach will lead my application to get an enormous amount of events to handle. This will slow down everything when the events start to get a lot. How can I limit the events just in few months depending on today date? <br>
  Hope to be clear. Any help?? <br><br></p>
  
  <p><strong>UPDATE 1</strong> (first problem and a small part of second are solved)
  ok I managed to pass to javascript my instance events array like this:</p>
  
  <pre><code>&lt;%= javascript_tag do %&gt;
    var events = &lt;%= raw @calendar_events.to_json %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This way I can limit the events the way I want simply in the controller via scoping.<br>
  When I check in browser console events array is composed this way:</p>
  
  <pre><code>[[" Snap-happy athletes ca...arrival at London 2012 ", "2012-07-28T00:00:00Z"], ["AdWords API Office Hours EMEA", "2012-07-25T00:00:00Z"], ["Under the math", "2012-07-22T00:00:00Z"], ["Superman power", "2012-07-13T00:00:00Z"], ["Google I/O 2012 Keynote","2012-07-01T00:00:00Z"]]
  </code></pre>
  
  <p>Which is an array made like this [["title", "date of the events"], ...] <br>
  <strong>But how can I put them in the datepicker with beforeShowDday??</strong> <br>
  <br>
  This is my first attempt but it's not working</p>
  
  <pre><code>$("#datepicker").datepicker({
    jQuery.each(events, function(index, event) {
      beforeShowDay: function(event[0]) {
        return [true, "", event[1]];
      }
    });
  });
  </code></pre>