Category: Rails

Extremely Simple Calendar Integration for Rails

Posted by on August 8, 2007

UPDATED 2008-11-19:

I didn’t update my blog for over a year, and as such decided to perform a reboot. The information previously contained on this page was out of date, and as such I didn’t keep it around. However, it turns out there’s a few places linking to this page, so I’ve decided to at least keep this from 404′ing.

The original blog post was centered around a plugin that you can now find at: http://code.google.com/p/calendardateselect

It really is a great plugin, and if you go to the site you’ll find it’s got very simple instructions on how to install and use it.

Good luck!

Update 2008-11-25:

Found the text of the old tutorial.

Today we’ll go over an extremely simple way to add a javascript/css calendar to your Rails app. We will be using the Calendar Date Select Plugin. It is a small, easy to use calendar based on the prototype library.

This was written back in the day for Rails 1.2, so take all this information with a grain of salt.

Installation is simple, and uses the typical installation syntax:
script/plugin install http://calendardateselect.googlecode.com/svn/tags/calendar_date_select

Voila! Installed!

Now, we just need to integrate it.

First, in your layout you need to add the javascript tag:
<%= calendar_date_select_includes “silver” %>

You can also use “red”, “blue” or “nil” for other color schemes.

Also note that you need to have prototype included as well, so if you haven’t already, you should also add the following to your layout:
<%= javascript_include_tag :defaults %>

And now, we’re ready to use it! Usage is simple. I was using it to keep track of an expiry date for a property, so I used to the following tag:
<%= calendar_date_select_tag “property[expiry_date]“, @property.expiry_date.to_s %>

If you wish, you can also check out the demo section for more information on using it with Form Builder.

Finally, I didn’t like the default ‘natural’ syntax for the date “August 8th, 2007″, so I changed it to use my preference, hyphenated syntax. To do this, open your environment.rb file and add the following line:
CalendarDateSelect.format = :hyphen_ampm

There! That is all I needed to do. Of course, there are more options, simply adding a :time => true will allow you to have a time field as well. There are a few more configuration options available for the calendar. You can find out more and get some more screenshots by visiting the project’s homepage.

Cascading Selects in Rails

Posted by on July 18, 2007

Update 2008-11-19:

I would like to apologize. After not updating my blog in almost a year, I decided to perform a reboot. During that time I decided that the information contained in this post was not current and decided not to keep it. It turns out that some people were linking here, despite the fact that I had only written two posts! I was quite happy to learn that, but sad to find out you were all getting 404s now.

I’m sad to say that the information is no longer available, and I’m not able to rewrite it with some more current information. However, it looks like you can find a better and more up to date tutorial here.