In Rails ActionMailer, you can send parameters to the mailer either by:
with() params:
Class MyMailer
def send_something
@user = User.find(params[:user_id])
..
end
end
MyMailer.with(user_id: user.id).send_something.deliver_now
or directly in the method call:
Class MyMailer
def send_something(user_id)
@user = User.find(user_id)
..
end
end
MyMailer.send_something(user.id).deliver_now
Are one of these methodologies preferred? Is there any advantage or disadvantage when the mailer is enqueued by a background job such as sidekiq which serializes all parameters to redis? I did note with https://guides.rubyonrails.org/action_mailer_basics.html, they only show the with() params way to do this. Is one of these ways an older style?
Using params is for sharing various things between methods. ActionMailer::Parameterized API explains that with an example.
It is not described in the guide.