Calendar Helper Plugin

This is a view plugin that can help developers with the creation of a simple calendar. Don’t think Google Calendar or Outlook but this will get you started. To install the plugin use the plugin install script:

script/plugin install

The plugin has a generate script that will create three CSS styles for the calendar.

script/generate calendar_styles

This CSS files will be saved in your rails app public/images/stylesheets/calendar directory. You will need to add one of these style sheets in your controller’s layout rthml file:

<%= stylesheet_link_tag 'calendar/blue/style' %>

Once you have added the right style sheet you can produce the HTML for a stylish calendar by adding the following line to an action’s rhtml view file.

<%= calendar :year =>, :month => %>

The Calendar Helper plugin supports a few other options in how and what is displays as for the days of the month. For example, to display each day of the month as link you can do the following:

calendar(:year =>, :month => do |d|
  link_to d.mday, :action => ...

The d variable is a Date instance so you will have the month, year, wday, yday, and other month functions at your disposal. Now, if you want to apply a CSS class on certains days you can replace the code in the block with something like this:

calendar(:year =>, :month => do |d|
  [link_to(d.mday, :action => ...), {:class => 'cssClass'}]

Technorati Tags: , , , , , ,

4 Responses to “Calendar Helper Plugin”

  • Luis Says:

    Very, very helpfull post. Saved me an evening of trying to recode the helper ;-) (Meant the link thingy)

  • Prabesh Says:

    Hi I want to use calendar_helper plugin.Can anyone provide me some references on how to use it.

  • TechKnow Says:

    @Prabesh – I thought this was a reference on how to use it…. LOL

    Plugins like these are not large framework or libraries, it would take me longer to list all references than it would take a capable programmer from looking through the code and figuring it out. Take a look a the code, it is open, it is a plain ol’ script!

  • Prabesh Says:

    I think this tutorial is a good reference point.Thanks for the suggestion,I will go try to go through the code.

Leave a Reply