Christopher Hart
2010-Sep-21 02:50 UTC
[iCalendar-devel] Question about using iCalendar in rake tasks
First, thanks for making iCalendar - I can''t imagine having to do this from scratch! I have a question I was hoping someone can help me with. I use iCalendar in one of my Rails models to generate iCalendar files when certain types of objects are created. This works fine within my Rails application, but I recently had the need to invoke one of the finders in the model through a rake task. The method called by the rake task never uses any iCalendar functionality, but when I invoke the task, I get the following error: $ rake appointment:upcoming_reminder --trace (in /Users/chris/dev/ss) ** Invoke appointment:upcoming_reminder (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute appointment:upcoming_reminder rake aborted! undefined method `all'' for Icalendar::Event:Class /Users/chris/dev/ss/app/models/event.rb:57:in `findEventsTomorrowForEmail'' /Users/chris/dev/ss/lib/tasks/notification.rake:6 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in `call'' ... The referenced line of the event model file is the invocation of a custom finder. Also within that model I require and include icalendar. Is it possible that somehow the include of Icalendar is causing this rake problem? Is there a way around it? Any suggestions are appreciated! Thanks, Chris I''m relatively new to creating rake tasks so I''m at a bit of a loss as to why this is happening. Could it have something to do with the -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/icalendar-devel/attachments/20100920/0091d3a1/attachment.html>
Sean Dague
2010-Sep-21 12:54 UTC
[iCalendar-devel] Question about using iCalendar in rake tasks
That''s a new one that I''ve not seen before, can you share the code that is triggering this? My guess it that something is empty or nil that you aren''t expecting, and that''s causing the issue. -Sean On 09/20/2010 10:50 PM, Christopher Hart wrote:> First, thanks for making iCalendar - I can''t imagine having to do this > from scratch! > > I have a question I was hoping someone can help me with. I use iCalendar > in one of my Rails models to generate iCalendar files when certain types > of objects are created. This works fine within my Rails application, but > I recently had the need to invoke one of the finders in the model > through a rake task. The method called by the rake task never uses any > iCalendar functionality, but when I invoke the task, I get the following > error: > > $ rake appointment:upcoming_reminder --trace > (in /Users/chris/dev/ss) > ** Invoke appointment:upcoming_reminder (first_time) > ** Invoke environment (first_time) > ** Execute environment > ** Execute appointment:upcoming_reminder > rake aborted! > undefined method `all'' for Icalendar::Event:Class > /Users/chris/dev/ss/app/models/event.rb:57:in `findEventsTomorrowForEmail'' > /Users/chris/dev/ss/lib/tasks/notification.rake:6 > /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in > `call'' > ... > > The referenced line of the event model file is the invocation of a > custom finder. Also within that model I require and include icalendar. > Is it possible that somehow the include of Icalendar is causing this > rake problem? Is there a way around it? > > Any suggestions are appreciated! > > Thanks, > Chris > > I''m relatively new to creating rake tasks so I''m at a bit of a loss as > to why this is happening. Could it have something to do with the > > > > _______________________________________________ > icalendar-devel mailing list > icalendar-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/icalendar-devel-- __________________________________________________________________ Sean Dague Learn about the Universe with the sean at dague dot net Mid-Hudson Astronomical Association http://dague.net http://midhudsonastro.org There is no silver bullet. Plus, werewolves make better neighbors than zombies, and they tend to keep the vampire population down. __________________________________________________________________
Christopher Hart
2010-Sep-21 15:48 UTC
[iCalendar-devel] Question about using iCalendar in rake tasks
Sure Sean. My model code (with a couple model names made generic by
find/replace):
require ''rubygems''
require ''icalendar''
require ''date''
class Event < ActiveRecord::Base
include Icalendar
belongs_to :model1
belongs_to :model2
belongs_to :model3
belongs_to :model4
attr_accessible :model4
after_save :sendIcalEmail
def sendIcalEmail
logger.debug "in sendIcalEmail"
if (!self.customer.nil? && self.customer.emailReminders == true)
#icalEvent = Icalender::Event.new
#icalEvent.start = DateTime.parse(self[:startTime])
#icalEvent.summary = summary "Appointment with " +
self[:model3].fullName + " for " + self[:model4].description
evstart = startTime.to_datetime
evend = endTime.to_datetime
evsummary = "Appointment at " + self.name
cal = Calendar.new
cal.event do
dtstart evstart
dtend evend
summary evsummary
location
alarm do
action "DISPLAY" # This line isn''t
necessary, it''s
the default
summary evsummary
trigger "-P1DT0H0M0S" # 1 day before
end
end
#cal.add_event(icalEvent)
#logger.debug cal.to_ical
CustomerNotifier.deliver_eventNotification(self.customer.email,
cal.to_ical)
logger.debug cal.to_ical
end
end
def self.findEventsTomorrow
tomorrow = Time.now.strftime("%Y-%m-%d")
Event.all :joins => [:model1, :model2, :model3, :model4], :conditions
=>
["startTime LIKE ?", "#{tomorrow}%"]
end
def self.findEventsTomorrowForEmail
tomorrow = Time.now.strftime("%Y-%m-%d")
nextDay = (Time.now + 1).strftime("%Y-%m-%d")
#Event.all :joins => [:model1, :model2, :model3, :model4], :conditions
=> ["startTime > #{tomorrow} and endTime < #{nextDay} and
emailReminders 1" ]
end
def self.findEventsTomorrowForSMS
tomorrow = Time.now.strftime("%Y-%m-%d")
nextDay = (Time.now + 1).strftime("%Y-%m-%d")
Event.all :joins => [:model1, :model2, :model3, :model4], :conditions
=>
["startTime > #{tomorrow} and endTime < #{nextDay} and smsReminders
= 1" ]
end
end
And the rake task:
namespace :appointment do
desc "Sends upcoming appointment reminders to clients"
task :upcoming_reminder => :environment do
events = Event.findEventsTomorrowForEmail
print "Sending upcoming appointment reminders"
events.each do |e|
print e.startTime + " " + e.endTime + " " +
e.customer.email
end
end
end
Thanks for your help,
Chris
On Tue, Sep 21, 2010 at 8:54 AM, Sean Dague <sean at dague.net> wrote:
> That''s a new one that I''ve not seen before, can you share
the code that is
> triggering this? My guess it that something is empty or nil that you
aren''t
> expecting, and that''s causing the issue.
>
> -Sean
>
>
> On 09/20/2010 10:50 PM, Christopher Hart wrote:
>
>> First, thanks for making iCalendar - I can''t imagine having to
do this
>> from scratch!
>>
>> I have a question I was hoping someone can help me with. I use
iCalendar
>> in one of my Rails models to generate iCalendar files when certain
types
>> of objects are created. This works fine within my Rails application,
but
>> I recently had the need to invoke one of the finders in the model
>> through a rake task. The method called by the rake task never uses any
>> iCalendar functionality, but when I invoke the task, I get the
following
>> error:
>>
>> $ rake appointment:upcoming_reminder --trace
>> (in /Users/chris/dev/ss)
>> ** Invoke appointment:upcoming_reminder (first_time)
>> ** Invoke environment (first_time)
>> ** Execute environment
>> ** Execute appointment:upcoming_reminder
>> rake aborted!
>> undefined method `all'' for Icalendar::Event:Class
>> /Users/chris/dev/ss/app/models/event.rb:57:in
`findEventsTomorrowForEmail''
>> /Users/chris/dev/ss/lib/tasks/notification.rake:6
>>
>>
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in
>> `call''
>> ...
>>
>> The referenced line of the event model file is the invocation of a
>> custom finder. Also within that model I require and include icalendar.
>> Is it possible that somehow the include of Icalendar is causing this
>> rake problem? Is there a way around it?
>>
>> Any suggestions are appreciated!
>>
>> Thanks,
>> Chris
>>
>> I''m relatively new to creating rake tasks so I''m at a
bit of a loss as
>> to why this is happening. Could it have something to do with the
>>
>>
>>
>> _______________________________________________
>> icalendar-devel mailing list
>> icalendar-devel at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/icalendar-devel
>>
>
>
> --
> __________________________________________________________________
>
> Sean Dague Learn about the Universe with the
> sean at dague dot net Mid-Hudson Astronomical Association
> http://dague.net http://midhudsonastro.org
>
> There is no silver bullet. Plus, werewolves make better neighbors
> than zombies, and they tend to keep the vampire population down.
> __________________________________________________________________
>
> _______________________________________________
> icalendar-devel mailing list
> icalendar-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/icalendar-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/icalendar-devel/attachments/20100921/0db64d0b/attachment-0001.html>
Christopher Hart
2010-Sep-23 13:47 UTC
[iCalendar-devel] Question about using iCalendar in rake tasks
I may have found a clue on this. If I change the methods in the model to
"self.find" or "self.all" instead of using the model name
(Event.find/Event.all), it works fine.
I''m relatively new to Ruby so I''m not exactly sure why this
matters. (Either
work fine if I comment out ''include Icalendar''.) Is it
possible that methods
invoked with Event.* are somehow getting picked up by the Icalendar module
due to the include? Thinking that this may be the case, I tried adding the
following to the Icalendar module but that didn''t solve the problem:
def self.included(base)
base.extend(ClassMethods)
end
I''m glad I have a workaround, but I''d still like to understand
why this
happened. If anyone has any ideas, I''d appreciate it. Thanks!
Chris
On Tue, Sep 21, 2010 at 11:48 AM, Christopher Hart <hartct at gmail.com>
wrote:
> Sure Sean. My model code (with a couple model names made generic by
> find/replace):
>
> require ''rubygems''
> require ''icalendar''
> require ''date''
>
> class Event < ActiveRecord::Base
> include Icalendar
>
> belongs_to :model1
> belongs_to :model2
> belongs_to :model3
> belongs_to :model4
>
> attr_accessible :model4
>
> after_save :sendIcalEmail
>
> def sendIcalEmail
> logger.debug "in sendIcalEmail"
> if (!self.customer.nil? && self.customer.emailReminders ==
true)
> #icalEvent = Icalender::Event.new
> #icalEvent.start = DateTime.parse(self[:startTime])
> #icalEvent.summary = summary "Appointment with " +
> self[:model3].fullName + " for " + self[:model4].description
> evstart = startTime.to_datetime
> evend = endTime.to_datetime
> evsummary = "Appointment at " + self.name
> cal = Calendar.new
> cal.event do
> dtstart evstart
> dtend evend
> summary evsummary
> location
> alarm do
> action "DISPLAY" # This line
isn''t necessary, it''s
> the default
> summary evsummary
> trigger "-P1DT0H0M0S" # 1 day before
> end
>
> end
>
>
> #cal.add_event(icalEvent)
> #logger.debug cal.to_ical
> CustomerNotifier.deliver_eventNotification(self.customer.email,
> cal.to_ical)
> logger.debug cal.to_ical
> end
> end
>
>
> def self.findEventsTomorrow
> tomorrow = Time.now.strftime("%Y-%m-%d")
> Event.all :joins => [:model1, :model2, :model3, :model4],
:conditions
> => ["startTime LIKE ?", "#{tomorrow}%"]
> end
>
> def self.findEventsTomorrowForEmail
> tomorrow = Time.now.strftime("%Y-%m-%d")
> nextDay = (Time.now + 1).strftime("%Y-%m-%d")
> #Event.all :joins => [:model1, :model2, :model3, :model4],
:conditions
> => ["startTime > #{tomorrow} and endTime < #{nextDay} and
emailReminders > 1" ]
> end
>
> def self.findEventsTomorrowForSMS
> tomorrow = Time.now.strftime("%Y-%m-%d")
> nextDay = (Time.now + 1).strftime("%Y-%m-%d")
> Event.all :joins => [:model1, :model2, :model3, :model4],
:conditions
> => ["startTime > #{tomorrow} and endTime < #{nextDay} and
smsReminders = 1"
> ]
> end
>
> end
>
> And the rake task:
>
> namespace :appointment do
> desc "Sends upcoming appointment reminders to clients"
> task :upcoming_reminder => :environment do
> events = Event.findEventsTomorrowForEmail
> print "Sending upcoming appointment reminders"
> events.each do |e|
> print e.startTime + " " + e.endTime + " " +
e.customer.email
> end
> end
> end
>
> Thanks for your help,
> Chris
>
> On Tue, Sep 21, 2010 at 8:54 AM, Sean Dague <sean at dague.net>
wrote:
>
>> That''s a new one that I''ve not seen before, can you
share the code that is
>> triggering this? My guess it that something is empty or nil that you
aren''t
>> expecting, and that''s causing the issue.
>>
>> -Sean
>>
>>
>> On 09/20/2010 10:50 PM, Christopher Hart wrote:
>>
>>> First, thanks for making iCalendar - I can''t imagine
having to do this
>>> from scratch!
>>>
>>> I have a question I was hoping someone can help me with. I use
iCalendar
>>> in one of my Rails models to generate iCalendar files when certain
types
>>> of objects are created. This works fine within my Rails
application, but
>>> I recently had the need to invoke one of the finders in the model
>>> through a rake task. The method called by the rake task never uses
any
>>> iCalendar functionality, but when I invoke the task, I get the
following
>>> error:
>>>
>>> $ rake appointment:upcoming_reminder --trace
>>> (in /Users/chris/dev/ss)
>>> ** Invoke appointment:upcoming_reminder (first_time)
>>> ** Invoke environment (first_time)
>>> ** Execute environment
>>> ** Execute appointment:upcoming_reminder
>>> rake aborted!
>>> undefined method `all'' for Icalendar::Event:Class
>>> /Users/chris/dev/ss/app/models/event.rb:57:in
>>> `findEventsTomorrowForEmail''
>>> /Users/chris/dev/ss/lib/tasks/notification.rake:6
>>>
>>>
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/rake-0.8.3/lib/rake.rb:617:in
>>> `call''
>>> ...
>>>
>>> The referenced line of the event model file is the invocation of a
>>> custom finder. Also within that model I require and include
icalendar.
>>> Is it possible that somehow the include of Icalendar is causing
this
>>> rake problem? Is there a way around it?
>>>
>>> Any suggestions are appreciated!
>>>
>>> Thanks,
>>> Chris
>>>
>>> I''m relatively new to creating rake tasks so I''m
at a bit of a loss as
>>> to why this is happening. Could it have something to do with the
>>>
>>>
>>>
>>> _______________________________________________
>>> icalendar-devel mailing list
>>> icalendar-devel at rubyforge.org
>>> http://rubyforge.org/mailman/listinfo/icalendar-devel
>>>
>>
>>
>> --
>> __________________________________________________________________
>>
>> Sean Dague Learn about the Universe with the
>> sean at dague dot net Mid-Hudson Astronomical Association
>> http://dague.net http://midhudsonastro.org
>>
>> There is no silver bullet. Plus, werewolves make better neighbors
>> than zombies, and they tend to keep the vampire population down.
>> __________________________________________________________________
>>
>> _______________________________________________
>> icalendar-devel mailing list
>> icalendar-devel at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/icalendar-devel
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/icalendar-devel/attachments/20100923/75afdbd8/attachment.html>