0
votes

I am attempting to add email notifications to my rails app. I just finished following the SendGrid Documentation for Ruby on Rails.

Here's what I have so far:

mailers/notifier.rb

class Notifier < ActionMailer::Base
  default from: "[email protected]"

  def send_reset_email(user)
    @user = user
    mail( :to => @user.email,
    :subject => 'Thanks for signing up for our amazing app' )
  end
end

It's use in my app

class ResetTokensController < ApplicationController
    def new
        if request.post?
            @user = User.find_by(email: params[:email])
            if @user && @user.id > 0
                @token = ResetToken.new
                @token.user_id = @user.id
                @token.token = BCrypt::Password.create("Aw3s0m3S@lt")
                Notifier.send_reset_email(@token.user).deliver
                if @token.save
                    redirect_to '/forgotpassword/sent'
                end
            else
            end
        end
    end
end

and the configuration in environment.rb

ActionMailer::Base.smtp_settings = { :user_name => '****', :password => '****', :domain => '*****.net', :address => 'smtp.sendgrid.net', :port => 587, :authentication => :plain, :enable_starttls_auto => true }

However, when I run the app, I'm getting this error:

NoMethodError in ResetTokensController#new
undefined method `send_reset_email' for Notifier:Class

What am I missing?

1

1 Answers

2
votes

The "send_reset_email" method is not a class-level method. Try:

Notifier.new.send_reset_email(@token.user).deliver