Action Mailer new DSL merged

Hi all,

Just letting you know we have a new DSL for Action Mailer.

class Notifier < ActionMailer::Base
delivers_from(“[email protected]”)

def signup_notification(recipient)
@account = recipient

attachments['an-image.jp'] = File.read("an-image.jpg")
attachments['terms.pdf'] = {:content => generate_your_pdf_here() }

mail(:to => recipient.email_address_with_name,
     :subject => "New account information")

end
end

Notifier.signup_notification(recipient).deliver

You can read all about it at:

http://lindsaar.net/2010/1/26/new-actionmailer-api-in-rails-3

Mikel


http://lindsaar.net/

Nice.

I’m not sure I understand the new API though. You define instance
methods but call class methods? Also, what’s that magic recipient
parameter we never pass in? Why not just define class methods? Eg:

class Notifier < ActionMailer::Base
delivers_from(“[email protected]”)

def self.signup_notification(recipient)
@account = recipient

attachments['an-image.jp'] = File.read("an-image.jpg")
attachments['terms.pdf'] = {:content => generate_your_pdf_here() }

mail(:to => recipient.email_address_with_name,
     :subject => "New account information")

end
end

And then do something like

Notifier.signup_notification(user).deliver

Cheers
-foca

Nice work!

On Tue, Jan 26, 2010 at 5:56 PM, steve ross [email protected] wrote:

Have you seen this: http://gist.github.com/281420

Of course, that was the result of the discussion in campfire we had
that hashed out the new DSL that José and I implemented :slight_smile:

One change on that though is that delivers_from is not there, and it
is replaced with a defaults hash.


http://lindsaar.net/

Just letting you know we have a new DSL for Action Mailer.

I think removing the magic #deliver_* and #create_* methods, and
returning an actual Mail object directly by an existing method makes a
lot of sense.

On the other hand, I think replacing methods like #body, #subject,
etc. with a hash is a missed idea, it’s harder to write and read, and
less clear to grasp, especially when you notice that ActiveRecord API
changes in exactly the opposite direction (from :conditions =>
conditions to #where(conditions), etc.).

Are there any more improvements planned on this or is that the final
version?


Bye,
Olek

Have you seen this: http://gist.github.com/281420

On Tue, Jan 26, 2010 at 10:29 PM, Olek [email protected]
wrote:

On the other hand, I think replacing methods like #body, #subject,
etc. with a hash is a missed idea, it’s harder to write and read, and
less clear to grasp, especially when you notice that ActiveRecord API
changes in exactly the opposite direction (from :conditions =>
conditions to #where(conditions), etc.).

Are there any more improvements planned on this or is that the final
version?

You don’t have to pass body as a hash, you pass the body in through
the template in 99% of the cases.

Think of the mail method as being analogous to the respond_to method
in Action Controller.

There are more changes coming, not big, but intelligent ones. Watch
this space :slight_smile:


http://lindsaar.net/