Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2012 05:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/2760680 to your computer and use it in GitHub Desktop.
Save anonymous/2760680 to your computer and use it in GitHub Desktop.
Calendar for the current month
class HomeController < ApplicationController
def index
@today = Date.today
@days_in_month = []
@days_in_month[@today.beginning_of_month.cwday] = (@today.beginning_of_month.day..@today.end_of_month.day).to_a
@days_in_month = @days_in_month.flatten.in_groups_of(7)
end
end
%table{border: 1}
%tr
- Date::DAYNAMES.each do |day_of_week|
%th= day_of_week
%tr
- @days_in_month.each do |week|
%tr
- week.each do |day|
%td=raw day ? day : "&nbsp;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment