I am trying to add a calendar to my rails app using table_builder. I based my implementation off of their readme and this highly recommended tutorial.
On the initial load, the calendar works beautifully. Each assignment is shown on the correct day. However, when the month is changed by clicking “>” or “<” which surround the month name, while the name of the month in the header is changed, the calendar itself is unchanged. Here is the block of code from my view that renders the calendar:
<div id="calendar">
<h2 id="month">
<%= link_to "<", :month => (@date.beginning_of_month-1).strftime("%Y-%m-01") %>
<%= h @date.strftime("%B %Y") %>
<%= link_to ">", :month => (@date.end_of_month+1).strftime("%Y-%m-01") %>
</h2>
<%= calendar_for(@assignments) do |calendar| %>
<%= calendar.head('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday') %>
<% calendar.day(:day_method => :due_date) do |day, assignments| %>
<%= day.day %>
<ul>
<% for assignment in assignments %>
<li>
<%= assignment.course.name %>: <%= link_to assignment.name, assignment_type_assignment_path(assignment.assignment_type, assignment)%>
</li>
<% end %>
</ul>
<% end %>
<% end %>
</div>
@assignments returns a complete list of all assignments associated with a given user. Each assignment as an attribute due_date which is the date we want the assignment to appear under in the calendar.
Here is the controller code:
class HomeController < ApplicationController
def index
@user = @current_user
@assignments = @user.assignments
@date = params[:month] ? Date.parse(params[:month]) : Date.today
end
end
Thanks
You aren’t passing the current
@dateto thecalendar_forhelper, so it’s simply defaulting to rendering the current (or some default) month. You’ll need to pass in@datelike this: