I''d like to execute some kind of before filter in my ActionMailer class... does anyone know how to do this? Specifically I let my users turn off email notifications, and I''d like to check their notification settings before any email gets sent. Seems like the wrong thing to do to have a million if statements lying all over the place whenever emails are delivered... Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Feb 15, 2008 at 10:02 AM, Jonzo <j.fantham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''d like to execute some kind of before filter in my ActionMailer > class... does anyone know how to do this?> Specifically I let my users turn off email notifications, and I''d like > to check their notification settings before any email gets sent. Seems > like the wrong thing to do to have a million if statements lying all > over the place whenever emails are delivered...You would be better off asking your users model for a list of people to send to who are subscribed. Your mailer part of the app has to find the user to get the email address, just set up a custom finder in the user model that refuses to give out the user object to the mailer if the user has unsubscribed on their record. Regards Mikel --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Are you thinking about newsletter situations? Ususally when I send an email I already have the user object in my hand (most of my emails are for things like watchlist changes, questions from other users, etc.), so an if statement to check whether the user wants to receive emails would be a lot cheaper than doing another database query. What about inside the mailer methods? can I return false or throw an exception and be sure that the email won''t be delivered? Is there any way to control whether the email is delivered from inside the mailer object instead of relying on the caller? On Feb 15, 12:12 pm, "Mikel Lindsaar" <raasd...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Fri, Feb 15, 2008 at 10:02 AM, Jonzo <j.fant...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I''d like to execute some kind of before filter in my ActionMailer > > class... does anyone know how to do this? > > Specifically I let my users turn off email notifications, and I''d like > > to check their notification settings before any email gets sent. Seems > > like the wrong thing to do to have a million if statements lying all > > over the place whenever emails are delivered... > > You would be better off asking your users model for a list of people > to send to who are subscribed. > > Your mailer part of the app has to find the user to get the email > address, just set up a custom finder in the user model that refuses to > give out the user object to the mailer if the user has unsubscribed on > their record. > > Regards > > Mikel--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Fri, Feb 15, 2008 at 10:29 AM, Jonzo <j.fantham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are you thinking about newsletter situations?Yes> Ususally when I send an email I already have the user object in my > hand (most of my emails are for things like watchlist changes, > questions from other users, etc.), so an if statement to check whether > the user wants to receive emails would be a lot cheaper than doing > another database query.Well, if you have done a @user = User.find(123) then doing @user.wants_email? shouldn''t generate another DB query as it should hit the ActiveRecord cache. Why can''t you just do: deliver_email if @user.subscribed and have a boolean value in your table called "subscribed" I think that would be about as clean and dry as can be. If you want to put it in your create_email method, you will have to make a method in your Notifier that creates the email but checks the users subscription status first.... Regards Mikel http://lindsaar.net/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah thanks Mikel, that''s what I ended up doing in the end. I created new methods in my mailer class that check to see if the user wants to be sent emails, if so then it''s sent, otherwise it''s stored in a messages table that the user can check next time they sign into the website. Thanks for the help and suggestions! On Fri, Feb 15, 2008 at 10:06 PM, Mikel Lindsaar <raasdnil-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On Fri, Feb 15, 2008 at 10:29 AM, Jonzo <j.fantham-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Are you thinking about newsletter situations? > > Yes > > > > Ususally when I send an email I already have the user object in my > > hand (most of my emails are for things like watchlist changes, > > questions from other users, etc.), so an if statement to check whether > > the user wants to receive emails would be a lot cheaper than doing > > another database query. > > Well, if you have done a @user = User.find(123) then doing > @user.wants_email? shouldn''t generate another DB query as it should > hit the ActiveRecord cache. > > Why can''t you just do: > > deliver_email if @user.subscribed > > and have a boolean value in your table called "subscribed" > > I think that would be about as clean and dry as can be. > > If you want to put it in your create_email method, you will have to > make a method in your Notifier that creates the email but checks the > users subscription status first.... > > Regards > > Mikel > http://lindsaar.net/ > > > > > >-- Jonathan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---