So I'm trying to make a mailer for my site that sends all of the users an email when an order is created. I'm not exactly sure how to go about it, so I've been trying a bunch of different things. Currently, I've screwed up so badly that I can't even get my app to start. (NOT GOOD.)
This is my error message: /Users/Brawain/rails_projects/sample_app/config/initializers/setup_mail.rb:12:in `': uninitialized constant DevelopmentMailInterceptor (NameError)
Currently, this is what my mailer looks like:
Orders controller
class OrdersController < ApplicationController
def new
def create
@order = Order.new(user_params)
if @order.save
UserMailer.work_order(@user).deliver
else
render 'new'
end
end
end
end
A new file I made called development_mail_interceptor.rb which is found in the config folder in the environments folder.
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.subject = "#{message.to} #{message.subject}"
message.to = "[email protected]"
end
end
The file work_order.text.rb in the views for the user_mailer just has text in it.
In the config folder in the initializers folder I have a file titled setup_mail.rb
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "student.andover.edu",
:user_name => "techmasterswork",
:password => "happycrazy",
:authentication => "plain",
:enable_starttls_auto => true
}
ActionMailer::Base.default_url_options[:host] = "localhost:3000"
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?
And then under app I have a folder called mailers where I have the file user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def work_order(user)
@user = user
mail to: user.email, subject: "Work Order Form"
end
end
I have a sneaking suspicion it should actually end up being order_mailer.rb, but I'm not sure. Anyway, I know this needs a lot of help. How would you fix this?
DevelopmentMailInterceptor
insideconfig/initializers
– Santhosh