I'm working on a Rails 5.1.2 app in Ruby 2.4.1. I'm creating a simple mailer to use as seen below in the class:
class PagingMailer < ApplicationMailer include SendGrid default from: Rails.application.secrets.no_reply_email
def message(paging_id, email)
@paging = Paging.find(paging_id)
mail to: email, subject: "#{@paging.user.username} has sent you a message via LogiCAD"
end
end
The message
method in the PagingMailer
class takes an argument of a paging_id
(integer) and gets passed the second argument for the email address (string). Originally I had this fired with a sidekiq worker and it wouldn't deliver giving a wrong number of arguments given 0 expected 2 exception.
So I fired up a rails console and tried to do a simple test, getting sidekiq out of the way just in case.
Loading development environment (Rails 5.1.2)
irb(main):001:0> PagingMailer.message(33, "john@domain.com").deliver
PagingMailer#message: processed outbound mail in 69.1ms
ArgumentError: wrong number of arguments (given 0, expected 2)
from app/mailers/paging_mailer.rb:5:in `message'
from app/mailers/paging_mailer.rb:7:in `message'
from (irb):1
The stacktrace points to line 5 and 7 in the message method which the common theme here is the email argument.
As a test I tried removing the second argument and hardcoding "john@domain.com" to the mail to: part so the method would only take a single argument of paging_id
. When I fire that from the Rails console I get the following:
irb(main):003:0> PagingMailer.message(33).deliver
PagingMailer#message: processed outbound mail in 27.4ms
ArgumentError: wrong number of arguments (given 0, expected 1)
from app/mailers/paging_mailer.rb:5:in `message'
from app/mailers/paging_mailer.rb:7:in `message'
I'm literally passing an argument to the method and it's not seeing it, even though it's being passed as an object.
It should be noted I have a few other mailers inside my app which are configured similarly to take 2 arguments and they perform properly. But this specific mailer I'm strugglebussing with.
Not sure if I'm missing something totally obvious, or if this might be some sort of Rails bug.
Any help you can provide is greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire