Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

has_calendar

> 编程语言
Open source

A view helper that creates a calendar using a table. You can easily add events with any content.

100 stars0 likes1 views
WebsiteGitHub

About

A view helper that creates a calendar using a table. You can easily add events with any content.

has_calendar

has_calendar is a view helper that creates a calendar using a table. You can easily add events with any content.

This plugin relies on the cal command, available on *nix systems. Instead of calculating dates, I parse the output.

NOTE: Only on Mac OS X (Unix?) the first day of week is Sunday; Linux (tested on Ubuntu) uses the argument -m, starting on Monday.

Want this to work on Windows systems? Make sure you have a command cal on your PATH that returns exactly the *nix output (haven't tested though).

Instalation

  1. Install the plugin with script/plugin install git://github.com/fnando/has_calendar.git

Usage

 2008, :month => 9 %>

or, if you want to register some events:

 2008, :month => 9 do |date| %>

As you can see, this will hit your database up to 31 times (one hit for each day) if you don't optimize it. Fortunately, you can use the options :events:

 Schedule.all do |date, events| %>

By default, each record will use the created_at attribute as date grouping. You can specify a different attribute with the option :field:

 Schedule.all, :field => :scheduled_at do |date, events| %>

By default, has_calendar will look for a date format called :day\_of\_week to use on the header of the calendar, you can change it using the :header_format option:

     :short_day_name %>

You can also change the caption provided by has_calendar (that defaults to the :default format):

     :short_day_name, :caption_format => :month_year %>

To set formats do something like this:

Date::DATE_FORMATS[:short_day_name] = '%a' # => (Sun..Sat)

Or on your locale file, if your application is internationalized.

You can set the HTML id: 'cal' %>

Formatting the calendar

You can use this CSS to start:

#calendar {
	border-collapse: collapse;
	width: 100%;
}

#calendar td,
#calendar th {
	color: #ccc;
	font-family: "Lucida Grande",arial,helvetica,sans-serif;
	font-size: 10px;
	padding: 6px;
}

#calendar th {
	border: 1px solid #ccc;
	background: #ccc;
	color: #666;
	text-align: left;
}

#calendar td {
	background: #f0f0f0;
	border: 1px solid #ddd;
}

#calendar span {
	display: block;
}

#calendar td.events {
	background: #fff;
}

#calendar td.today {
	background: #ffc;
	color: #666;
}

#calendar caption {
  display: none;
}

TO-DO

  • Write some specs as soon as possible!

Contributors

  • Carlos Júnior (xjunior)

Copyright (c) 2008 Nando Vieira, released under the MIT license

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言