Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Ivan Storck http://www.ivanenviroman.com

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

View Code for Calendar Helper

This is the view template for an action that has all the events in @events
it links to the event, too ( I used the trestle generator, and the calendar helper plugin )

   1  
   2  <%=
   3  calendar({:year => @year, :month => @month}) do |d|
   4    cell_text = "#{d.mday}<br />" 
   5    cell_attrs = {:class => 'day'}
   6    @events.each do |e|
   7      if e.starts_at.mday == d.mday
   8        cell_text << link_to( e.title, :action => 'show', :id => e ) << "<br />" 
   9        cell_attrs[:class] = 'specialDay'
  10      end
  11    end
  12    [cell_text, cell_attrs]
  13  end
  14  %>


Here is the controller action snippet if you need it. This could probably be improved by only finding the events in the certain month you are looking at.

   1  
   2    def show
   3      @event = Event.find(params[:id])
   4    end
   5    
   6    def calendar
   7      @year = @params[:year].to_i
   8      @month = @params[:month].to_i
   9  
  10      @events = Event.find(:all)
  11    end


Here is my migration for my events table.
   1  
   2  class CreateEvents < ActiveRecord::Migration
   3    def self.up
   4      create_table :events do |t|
   5         t.column "title", :string
   6         t.column "description", :text
   7         t.column "starts_at", :datetime
   8         t.column "ends_at", :datetime
   9         t.column "recurring", :boolean
  10         t.column "created_by", :string
  11         t.column "updated_by", :string
  12         t.column "updated_on", :datetime
  13         t.column "created_on", :datetime
  14      end
  15    end
  16  
  17    def self.down
  18      drop_table :events
  19    end
  20  end
  21  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS