![]() 2.3 Complete List of Action Mailer User-Settable Attributes bcc The resulting object is then sent the deliver! method, which well… delivers it. Hence, if the method name starts with deliver_ followed by any combination of lowercase letters or underscore, method_missing calls new on your mailer class ( UserMailer in our example above), sending the combination of lower case letters or underscore, along with the parameters. When /^deliver_(\w*)/ then new($1, *parameters).deliver! When /^create_(\w*)/ then new($1, *parameters).mail Looking at the ActionMailer::Base source, you will find this:ĭef method_missing(method_symbol, *parameters)#:nodoc: Rather, your delivery instance methods are automatically wrapped in class methods that start with the word deliver_ followed by the name of the mailer method that you would like to deliver. So how does Action Mailer understand this deliver_welcome_email call? If you read the documentation ( README.html), you will find this in the “Sending Emails” section: 2.2 Action Mailer and Dynamic deliver_ methods The next section will go through how Action Mailer achieves this. In UserMailer, we defined a method called welcome_email, and so we deliver the email by calling deliver_welcome_email. Let’s see how we would go about wiring it up using an observer:Ĭlass UserObserver. This way, whichever way a user is created (from a web form, or from an API call, for example), we are guaranteed that the email will be sent. Not because it’s wrong, but because it keeps your controller clean, and keeps all logic related to the user model within the user model. ![]() Whether you use the second or third methods is up to you, but staying away from the first is recommended. One is to send the email from the controller that sends the email, another is to put it in a before_create callback in the user model, and the last one is to use an observer on the user model. 2.1.4 Wire It Up So That the System Sends the Email When a User Signs Up Rails sets the content type of the email to be the one in the filename. Had we wanted to send text-only emails, the file would have been called welcome_. To login to the site, just follow this link. You have successfully signed up to, and your username is. This will be the template used for the email, formatted in HTML: 2.1.3 Create a Mailer ViewĬreate a file called welcome_ in app/views/user_mailer/. Thus, in our example the mailer view will have a and a instance variables available. The keys of the hash passed to body become instance variables in the view. It can be a string or, if there are multiple recipients, an array of strings For a full list of all available options, please have a look further down at the Complete List of ActionMailer user-settable attributes section. Here is a quick explanation of the options presented in the preceding method.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |