Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## calendars_controller.rb
- class CalendarsController < ApplicationController
- # GET /ui_prototype
- def index
- @dates = dates_of_month today.year, today.month
- end
- protected
- # Return an array of days from sunday to saturday of the given month
- # and year, includes previous and next months / years if needed
- def dates_of_month(year, month)
- first = Date.new(year, month, 1)
- last = Date.new(year, month + 1, 1) - 1
- start_date = first - first.wday
- end_date = last + (6 - last.wday)
- dates = Array.new
- start_date.upto(end_date) do |d|
- dates.push(d)
- end
- return dates
- end
- end
- ## calendars_helper.rb
- module CalendarsHelper
- def date_dom_id(date)
- return "#{date.year}_#{date.month}_#{date.day}"
- end
- def date_dom_class(date, week)
- return "calendar-datecell-week-5-day-6" if week == 5 and date.wday == 6
- return "calendar-datecell-week-5" if week == 5
- return "calendar-datecell-day-6" if date.wday == 6
- return "calendar-datecell"
- end
- end
- ## index.rhtml
- <div id="calendar_container">
- <%
- week = 1
- @dates.each do |d|
- %>
- <div id="<%= date_dom_id(d) %>" class="<%= date_dom_class(d, week) %>">
- <div id="<%= "day_#{date_dom_id(d)}" %>" class="calendar-day"><%= d.day -%></div>
- </div>
- <%
- end
- %>
- </div>
- ## error message
- NoMethodError in Calendars#index
- Showing app/views/calendars/index.rhtml where line #4 raised:
- You have a nil object when you didn't expect it!
- You might have expected an instance of Array.
- The error occurred while evaluating nil.each
Add Comment
Please, Sign In to add comment