Forum: Ruby on Rails ROR Mailers- Newby to Ruby needs help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
001a370d8a0a7ba50987a875c665e80e?d=identicon&s=25 Nicole Morales (Guest)
on 2014-11-11 17:17
(Received via mailing list)
Hi all

Im pretty new to Ruby on Rails.  My boss created an app and is asking me
to
create a worker to email us when there is a conflict of events for a DJ.
It
works in the terminal but Im having problems getting the event details
of
the conflict to display in my mailer.  Im trying to test it out with
mail
catcher to see if Im doing it correctly but I do not know what to pass
for
the overlaps parameter in my test.  Below is my code. Can someone help
me
out?

My worker says this(PLEASE LOOK AT THE CAPS)

*class TalentConflictsWorker*
*    include Sidekiq::Worker*
*    include Sidetiq::Schedulable*
*    sidekiq_options retry: false*

*    MAX_CALENDARS_TO_SCHEDULE_AT_ONCE=10*


*    def perform (user_id)*

*        user=User.find(user_id)*
*        events=user.calendar.events*
*        events.each do |e|*
            #Checking for conflicting events. If not the same event and
has
an overlap, display name and start date.
         *   overlaps=events.where("(strftime('%s',start) -
strftime('%s',?)) * (strftime('%s',?) - strftime('%s',end)) >= 0" ,
e.start, e.end ).where.not(id: e.id <http://e.id/>)*
*            overlapsflag=overlaps.present?*
            #overlaps=where("(start,events.end) OVERLAPS (timestamp ?,
timestamp ?)" AND not(id: e.id).present?

         *   if overlapsflag*

*                CalendarMailer.talent_conflict(user, events,
overlaps).deliver*

                *#FOR TERMINAL <---THIS WORKS IN THE TERMINAL (when
uncommented) MY ISSUE IS HOW DO I PASS THE OVERLAPS AND GET THOSE EVENTS
TO
DISPLAY IN THE EMAIL*
                #puts "Conflict found", e.name, e.start
                #overlaps.each do |overlap_event|
                #puts overlap_event.name
                #puts overlap_event.start
                #overlapstring=overlap_event.to_s
                #end
            #else
                #puts "NO EVENT CONFLICT FOUND"
  *          end           *
*        end       *
*    end*
*end*

*Heres the mailer I THOUGHT PERHAPS I PUT THE DO LOOP IN THE MAILER? *

*def talent_conflict(user, events, overlaps)*
*        @user=user*
*        @events=events*
*        @overlaps= overlaps*
*        overlaps.each do |overlap_event|*
*                puts overlap_event.name <http://overlap_event.name/>*
*                puts overlap_event.start*
*                #overlapstring=overlap_event.to_s*
*            end*
*        mail(subject: "SMG Talent: detected an event conflict )")*
*    end*

*THIS IS THE HTML *

*<p>Event conflicts have been detected.</p>*

*<ul>*

*<li><%= @events.name <http://events.name/> %> held on <%= @events.start
%>
conflicts with the following event: <%= @overlaps.name
<http://overlaps.name/> %><%= @overlaps.start %></li>*


*</ul>*
4c6bde00168d595053c09aac7e487f8e?d=identicon&s=25 Colin Law (Guest)
on 2014-11-11 17:23
(Received via mailing list)
On 11 November 2014 16:13, Nicole Morales <nmorales59@gmail.com> wrote:
> Heres the mailer I THOUGHT PERHAPS I PUT THE DO LOOP IN THE MAILER?
>
> def talent_conflict(user, events, overlaps)
>         @user=user
>         @events=events
>         @overlaps= overlaps
>         overlaps.each do |overlap_event|
>                 puts overlap_event.name

puts outputs to the server terminal window, you presumably want to add
it to the text of the email instead.

Colin
This topic is locked and can not be replied to.