View Code For Calendar Helper
Join the DZone community and get the full member experience.
Join For FreeThis 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 )
<%=
calendar({:year => @year, :month => @month}) do |d|
cell_text = "#{d.mday}
"
cell_attrs = {:class => 'day'}
@events.each do |e|
if e.starts_at.mday == d.mday
cell_text << link_to( e.title, :action => 'show', :id => e ) << "
"
cell_attrs[:class] = 'specialDay'
end
end
[cell_text, cell_attrs]
end
%>
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.
def show
@event = Event.find(params[:id])
end
def calendar
@year = @params[:year].to_i
@month = @params[:month].to_i
@events = Event.find(:all)
end
Here is my migration for my events table.
class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.column "title", :string
t.column "description", :text
t.column "starts_at", :datetime
t.column "ends_at", :datetime
t.column "recurring", :boolean
t.column "created_by", :string
t.column "updated_by", :string
t.column "updated_on", :datetime
t.column "created_on", :datetime
end
end
def self.down
drop_table :events
end
end
Calendar (Apple)
Opinions expressed by DZone contributors are their own.
Comments