Class: Notifications

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/notifications.rb

Overview

Use this mailer to send notifications eg for newly created pages, sign ups and so on.

Instance Method Summary (collapse)

Instance Method Details

- (Object) account_confirmed(user)

Inform the admin if a user confirms an account



25
26
27
28
29
# File 'app/mailers/notifications.rb', line 25

def (user)
  @notify_subject = "USER CONFIRMED ACCOUNT AT #{APPLICATION_CONFIG['name']}"
  @user = user
  mail( :to => APPLICATION_CONFIG['admin_notification_address'], :subject => @notify_subject)
end

- (Object) cancel_account(user_info)

Inform the admin when a user cancel an account.



18
19
20
21
22
# File 'app/mailers/notifications.rb', line 18

def ()
  @user_info = 
  @notify_subject = "USER CANCELED ACCOUNT AT #{APPLICATION_CONFIG['name']}"
  mail( :to => APPLICATION_CONFIG['admin_notification_address'], :subject => @notify_subject)
end

- (Object) invite_user(invitation, subject, message)

Invite User arg[0] = Invitation-id



90
91
92
93
94
95
96
97
98
# File 'app/mailers/notifications.rb', line 90

def invite_user(invitation,subject,message)
  @subject = subject
  @sign_up_url = new_user_registration_url(:token => invitation.token)
  @invitation = invitation
  @message = message
  mail( :from => invitation.user.,
        :to   => invitation.,
        :subject => subject )
end

- (Object) new_comment_created(recipient, title, from_mail, from_name, comment, link_to_commentable)

Infrom owner of commentable, and admin when a comment was posted arg[0] = recipient, arg[1] = commentable.title, arg[2] = email, arg[3] = name, arg[4] = comment



76
77
78
79
80
81
82
83
84
85
86
# File 'app/mailers/notifications.rb', line 76

def new_comment_created(recipient,title,from_mail,from_name,comment, link_to_commentable)
  @notify_subject = "Your entry '#{title}', was commented by #{from_name}"
  @comment   = comment
  @from_name = from_name
  @from_mail = from_mail
  @link_to_commentable = link_to_commentable
  mail( :from => from_mail,
        :to => [APPLICATION_CONFIG['admin_notification_address'],recipient].uniq,
        :subjcect => @notify_subject
  )
end

- (Object) new_posting_created(blog_id, posting_id)

Inform admin when new postings created



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/mailers/notifications.rb', line 32

def new_posting_created(blog_id,posting_id)
  blog      = Blog.find(blog_id)
  posting   = blog.postings.find(posting_id)
  @blogtitle= blog.title
  @title    = posting.title
  @username = posting.user.name
  @content  = posting.render_for_html(body).html_safe
  @url      = blog_posting_url(blog,posting)
  @notify_subject = "A NEW POSTING WAS CREATED AT #{APPLICATION_CONFIG['name']}"

  begin
    # Attach cover picture
    if posting.cover_picture_exists?
      if File.exist?(filename=posting.cover_picture.path)
        attachments[File::basename(filename)] = File.read(filename)
      end
    end

    # TODO: The following code doesn't work. Either there is a bug somewhere
    # TODO: in CBA or in Rails::Mail. Only the cover-pic arrives.
    # TODO: Check if it's possible to attach more files with Rails Mail - it should!
    # Attach attachments
    posting.attachments.each do |att|
      path = att.file.path.gsub(/\?.*$/,"")
      file = File::basename(path)
      if File.exist?(path)
        attachments[file] = File.read(path)
      end
    end
  rescue => e
    msg = "<br/><br/>*** ERROR ATTACHING FILE #{e.to_s} **** #{__FILE__}:#{__LINE__}"
    @content += msg.html_safe
    puts msg
  end

  mail( :to => APPLICATION_CONFIG['admin_notification_address'], :subject => @notify_subject)
end

- (Object) sign_up(new_user)

When a new user signed up, inform the adminstrator



11
12
13
14
15
# File 'app/mailers/notifications.rb', line 11

def (new_user)
  @user = new_user
  @notify_subject = "NEW SIGN UP AT #{APPLICATION_CONFIG['name']}"
  mail( :to => APPLICATION_CONFIG['admin_notification_address'], :subject => @notify_subject)
end