notification message

32 views
Skip to first unread message

Joe Guerra

unread,
Sep 27, 2017, 6:32:03 PM9/27/17
to Ruby on Rails: Talk
Just curious, I'd like to shoot off a notification message once a form has been entered on my site.

I guess it's easy enough to figure out.  Do I just create a mailer and call that task once it's completed?
(sorry I haven't worked with any mailers yet.)

Thanks,
Joe

Joe Guerra

unread,
Sep 27, 2017, 7:43:13 PM9/27/17
to Ruby on Rails: Talk
Ok, I think I've got it figured out.  

Thanks,
Joe

Mugurel Chirica

unread,
Oct 6, 2017, 12:20:18 PM10/6/17
to rubyonra...@googlegroups.com
You can post your solution, maybe it will help others in the future.

Joe Guerra

unread,
Oct 6, 2017, 7:18:57 PM10/6/17
to Ruby on Rails: Talk
oh, it wasn't too hard.


basically generated a mailer 

'rails generate mailer Interview_Notification'

it created the mailer(s) and views I needed.



class InterviewNotificationMailer < ActionMailer::Base

default from: "jgu...@jginfosys.com"

# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.interview_notification_mailer.interview_request.subject
#
def interview_request
@greeting = "Hi, you have an interview request."

mail to: "jgu...@jginfosys.com", subject: "Interview request!"
end

end


In my Interviews controller, in the create def, if the interview request is saved... I fired off the mailer...
InterviewNotificationMailer.interview_request.deliver

I didn't make any changes to the mailer view.  You have to make sure you call the mailer correctly (the class, followed by def, and the action (.deliver))

That's it.

Joe Guerra

unread,
Oct 6, 2017, 7:57:49 PM10/6/17
to Ruby on Rails: Talk
Oh, I almost forgot.  There are necessary additions needed to send mail from your production environment (heroku in my case).

I used the gem 'sendgrid-ruby'... 

You need to add the sendgrid resource on heroku (enable it)

need to add this configuration to the production environment...

config.action_mailer.default_url_options = { :host => 'www.jginfosys.com', :protocol => 'https'
}

and added this to the ... environment.rb


ActionMailer::Base.smtp_settings = {
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'www.jginfosys.com',
:address => 'smtp.sendgrid.net',
:port => 587,
:authentication => :plain,
:enable_starttls_auto => true
}

Of course, change your host and domain to match yours.

On Wednesday, September 27, 2017 at 6:32:03 PM UTC-4, Joe Guerra wrote:
Reply all
Reply to author
Forward
0 new messages