renz45 / mandrill_mailer

A small gem for sending Mandrill template emails
260 stars 84 forks source link

problem with template_content key in mandrill_mail(args) #125

Closed stanams closed 7 years ago

stanams commented 7 years ago

I'm using mandrill templates that I have made on mailchimp mail editor then exported to mandrill. However, I have this error when doing my tests:

NoMethodError:
   method `map' for nil:NilClass
# /home/rof/cache/bundler/ruby/2.2.0/gems/mandrill_mailer-0.2.1/lib/mandrill_mailer/template_mailer.rb:267:in `mandrill_args'

I understand that this error comes from the fact that I don't have args[:template_content] in my .mandril_mail(args) method. However, it's not said in the documentation that args[:template_content] is mandatory. Also, I guess that the content of the mailer is taken from the template I imported to mandrill.

So I don't understand what is wrong. Here is in my mandrill mailer WelcomeMailer.rb:

def send_welcome_email(user)
  mandrill_mail(
      template: 'bon-template-inscription',
      subject: "Bienvenue sur Foodle !",
      to: user.email,
      inline_css: true,
      important: true
  )
end

which is simply called on my users_controller.rb:

 if @user.save
     WelcomeMailer.send_welcome_email(@user).deliver_now
     render json: @user, serializer: Api::V1::SessionSerializer, status: 201, root: nil
 else
     render json: { errors: @user.errors.messages }, status: :unprocessable_entity
 end

Could you please help me ? :)

renz45 commented 7 years ago

Hi Stan, I apologize for taking so long to get back to you, I've been on vacation the last two weeks.

It looks like you're on a pretty old version of this gem. You could try bumping it to a slightly newer version, like 0.6.1 and see if it's fixed there. Alternatively, the only other thing I can think of (other then updating the gem) would be to try passing an empty array for that template_content attribute.

stanams commented 7 years ago

Hi @renz45 thanks for your insight, indeed, upgrading the version of the gem solved the issue (without needing to pass an empty array). I just don't understand why the default version I got was not among last year releases, but anyway. Thanks!

renz45 commented 7 years ago

Great! I'm glad it worked :)