Displaying an array of events in full calendar

I am trying to integrate the arshaw’s jqurey fullcalendar into my rails
application. When I click on the calendar tab it should display the
calendar with the list of tasks in the database on the corresponding
date.

In Calender Controller

    def index

    @task=Task.find_all_by_pm_id(params[:u])
      @task.each do |t|
        @task_name=t.task_name
        @end_date=t.due_date
      end
    end

In the Calenders/index.html.erb

    <script>
     $(document).ready(function() {
    var date = new Date();
    var d = <%=@end_date.day%>;
    var m = <%=@end_date.month%>-1;
    var y = <%=@end_date.year%>;
    var calendar = $('#calender').fullCalendar({
      header: {
        left: 'prev,next today',
        center: 'title',
        right: 'month,agendaWeek,agendaDay'
      },
      selectable: true,
      selectHelper: true,
      events: [
        {
          title: '<%=@task_name%>',
          start: new Date(y, m, d)
        },

      ],
      editable: true

    });

  });

</script>

Now it is displaying only the last task name. I need to display all the
task name on particular dates.I guess i need to loop all the tasks and
then display it in the title field. But I am not sure how to do it. I am
new to ROR. Any inputs on this will be appreciated.
Please help

On Sep 26, 2012, at 5:00 AM, ruby rails wrote:

     @task.each do |t|
       @task_name=t.task_name
       @end_date=t.due_date

Right here, you are looping over the tasks and assigning them (one after
another) to the same variable. You’re overwriting the singular variable
each time, which is why you end up with only one (the last) task.

Not sure how your view wants to get these, but I would put them in a
hash or an array for transport to the view.

   var y = <%=@end_date.year%>;
         title: '<%=@task_name%>',

Now it is displaying only the last task name. I need to display all the
task name on particular dates. Any inputs on this will be appreciated.
Please help

HTH,

Walter