I have seen couple of sites and they have demonstrated how to use the helper with special day
<%= calendar({:year => @year, :month => @month}) do |d|
cell_text = "#{d.mday}<br />"
cell_attrs = {:class => 'day'}
@events.each do |e| if e.startdate == d
cell_text << e.name << "<br />" cell_attrs[:class] = 'specialDay' end
end [cell_text, cell_attrs] end %>
http://snippets.dzone.com/posts/show/2488
Both the code seems to be fine,but they didnt achieve the sample one Ruby onrailsworkshops.With the help of my friends Air and Mein i achieved the dynamic calendar.Here i listed my code.
First get the helper plugin from
svn: http://topfunky.net/svn/plugins/calendar_helper
Application Helper
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def pre
link_to (image_tag('previous.png',:alt=>'Previous')),:date=>@date.last_month
end
def nex
link_to (image_tag('next.png',:alt=>'Next')),:date=>@date.next_month
end
end
Events Controller
class EventsController < ApplicationController
layout 'base'
def index
@date=params[:date] ? params[:date].to_date : Date.today
@events=Event.all
end
def add
end
end
Views
<%days,texts,descs = Event.all.collect {|e| e.date } ,Event.all.collect {|e| content_tag(:br, e.name)},Event.all.collect {|e| e.description}%>
<%=calendar(:year => @date.year,:previous_month_text=>pre,:month =>@date.month,:next_month_text=>nex) do |d|
if days.include?(d)
index=days.index d
[d.mday, {:class => "specialDay",:onmouseover=>"Element.update('day_detail','#{days[index].strftime('%b %d')}#{texts[index]}#{descs[index]}')",:onmouseout=>"Element.update('day_detail', null)"}]
else [d.mday, {:class => "day"}] end
end %>
Final view

I used your code and for some reason. Events cannot be displayed. Also is it possible display a multiple day event by having a start date and end date.
ReplyDeletecan i get ur contact id so that i will send the whole code
ReplyDelete