All threads / Forum Series Part 5: Email Notifications with Rails 4.2, deliver_later, and Previews Discussion

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Forum Series Part 5: Email Notifications with Rails 4.2, deliver_later, and Previews Discussion

Innokenty Longway ·

Thanks for sharing this. Didn't know about it.

Reply

I have no audio from 10:05 to 11:05. Is that an issue with the screencast or just a particularly reflective section? :)

Well shoot. That's definitely missing audio. I may not have the original audio to get that fixed unfortunately. Looks like I'm just explaining that you can set the anchor and your emails can link to and highlight the specific element on the page when you click the link.

Ok, that makes sense. Thanks!

Another issue I'm running into is this:

[ActiveJob] [ActionMailer::DeliveryJob] [ea357c97-e2f4-42c4-aa5f-393469e9f6b5] Performing ActionMailer::DeliveryJob from SuckerPunch(mailers) with arguments: "AdminsMailer", "job_posted", "deliver_now", gid://myapp/Job/28

^^ my console output from ActiveJob. It's showing "deliver_now" as an argument even though my code looks like this: CustomerMailer.job_posted(@job).deliver_later

So my Jobs#create action is still waiting for these emails to be sent before redirecting.

Reply

We can no longer use `deliver_now` or `deliver_later` with preview as it will throw an Net::OpenTimeout error. "Methods must return a Mail::Message object which can be generated by calling the mailer method without the additional deliver." http://api.rubyonrails.org/...

Very good to know! Thanks @Marklar

What should you do instead now?

Just leave that part out. For example:

class NotifierPreview < ActionMailer::Preview
def welcome
Notifier.welcome(User.first)
end
end

Reply
Kohl Kohlbrenner ·

@excid3:disqus in the send notifications method, could you sub current_user for user when subtracting from the unique list? Does [user] reflect :user in belongs_to :user relationship?

Yes it does. It's basically creating an array with one item in it and that item is the User from the belongs_to relationship. You can't do "current_user" because it's a method that's only available in the controllers and views. In the model here, we only have access to the current ForumPost record and it's associations.

Kohl Kohlbrenner ·

@excid3:disqus thanks! One more thing: is there an implicit 'self' before forum_thread.users.uniq - users? I would think so.

The only real time you need to use "self" in the model methods is when you want to assign an attribute. Not using self will create local variables. If you're just working with the values and not changing them, you don't have to use "self".

Kohl Kohlbrenner ·

right. I understand the reasoning as to why you didn't include it, but it is "there", correct?

Kohl Kohlbrenner ·

i.e. self.forum_thread.users.uniq - users

Yep, I believe so. Python makes it always explicit, but it can be a little confusing in Ruby since it isn't required to access but it is require to set attributes.

Kohl Kohlbrenner ·

Also, are smtp settings already set up here? Do we need to use mandrill or some other client that you didn't show?

Yeah they are. Check out the Mandrill episode to see how I set that up. https://gorails.com/episode...

Reply

Hi oliver I just installed sucker_punch so that my email should deliver later... but three days passed not delivered.. By deliver now.... it always delivered... Am I missing something???

Reply
Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.