Hi -- On Fri, 7 Aug 2009, pharrington wrote:
> > On Aug 7, 11:54 pm, Phlip <[email protected]> wrote: >> Ilan Berci wrote: >>> While not knowing your problem domain at all, I have a preference for >>> thin dumb controllers (that fit easily within REST), I would move the >>> mailer down into models/ or lib/ >> >>> hth >>> ilan >> >> +1 (FWIW!) >> >> Views should be dumb, Controllers thin, and Models fat. >> >> If the deliver_ call were one line, it qualifies for the Controller. But... >> >> The delivered template is itself a View. Hence it should be dumb. Hence >> anything >> powering it belongs in the _Model_, where fat things belong. >> >> -- >> Phlip > > > Opinions opinions, oh my! > > As I guess has been the general theme of this thread, it really > depends on the context in which the mailing is taking place. If its as > simple as user clicking a button on your site and in turn some mail > goes out, that's controller domain. But if the mailing is part of some > more complex logic (simple example: user signs up; requested name > needs to be checked, perhaps an invite token counter needs to be > decremented, maybe you'll queue this ish etc, and the email goes out > at the end), then you'll call the mailer in the part of the model that > handles that processing. Send an emailing is a *general enough > activity* that there are no rules that say where you should do it in > the MVC context. I agree, and I think part of the answer too is that ActionMailer *already* deals with these questions. Controllers are allowed to make use of the models' APIs. Having a fat model philosophy doesn't mean you can't do this: Thing.find(params[:id]) in the controller. Similarly, given an ActionMailer model, there's no reason at all not to use its API in the controller. If there's more complexity to the mailing -- for example, if it has to search and filter for particular users before it emails them -- then *that* logic can be put in a model. In other words, rather than this in a controller: User.find(:all, :conditions => ["staff = ?", true]).each do |staff| Notifier.deliver_whatever(staff) end you would certainly push both the specialized find operation and the delivery into a model, so the controller could just do this: User.mail_to_staff or Notifier.notify_staff But in the simple case, where all you need to do is call a single class method of ActionMailer, there's no reason not to just call it from the controller. David -- David A. Black / Ruby Power and Light, LLC / http://www.rubypal.com Q: What's the best way to get a really solid knowledge of Ruby? A: Come to our Ruby training in Edison, New Jersey, September 14-17! Instructors: David A. Black and Erik Kastner More info and registration: http://rubyurl.com/vmzN --~--~---------~--~----~------------~-------~--~----~ 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

