Skip to content

Quickstart from scratch

eviii edited this page Oct 13, 2012 · 3 revisions

Create a new rails project, display a calendar, and optionally create some events.

(This is using Rails 3 and SQLite. If using RVM you may need to install the Rails gems first.)

Bring up a calendar

  1. rails new cal_test
  2. cd cal_test
  3. gem install event-calendar
  4. Add to Gemfile: gem 'event-calendar', :require => 'event_calendar'
  5. rails generate event_calendar
  6. rake db:migrate
  7. rails server

Hooray! A calendar should now be running at http://localhost:3000/calendar

In your view or layout you'll probably want to include the generated javascript:

  <%= javascript_include_tag 'event_calendar' %>

(The stylesheet should be included by the stylesheet_link_tag :all method in the layout.)

Manage events

The plugin is only concerned with displaying 'event' objects that at a minimum have start_at and end_at fields. The generator created some helpful MVC code to get you started, but leaves creating/editing/deleting events up to you. Let's use the Rails scaffold generator to get some basic event management up and running.

  1. For expediency, let's remove the migration the event_calendar generator created. This will let us run the following scaffold. (We could have just run this before the event_calendar generator in the 'Bring up a calendar' steps.)
  2. Run the scaffold:
  rails generate scaffold Event name:string start_at:datetime end_at:datetime

(No need to overwrite the event.rb model.) 3. Make sure to have those two lines in your event.rb

  attr_accessible :end_at, :name, :start_at
  has_event_calendar
  1. Now we can manage events at http://localhost:3000/events
  2. Create an event or two and return to http://localhost:3000/calendar to view them.
  3. Remove or modify scaffold.css in public/stylesheets as it changes the color of hovered links.

Hooray! Now we have a calendar displaying some events.