© Stefan Wintermeyer 2018
Stefan WintermeyerLearn Rails 5.2https://doi.org/10.1007/978-1-4842-3489-1_11

11. Action Mailer

Stefan Wintermeyer1 
(1)
Bochum, Germany
 

Even if you mainly use Ruby on Rails to generate web pages, it sometimes is useful to be able to send an e-mail.

So, let’s build an example with minimal user management for a web shop that automatically sends an e-mail to the user when a new user is created, as shown here:

$ rails new webshop
  [...]
$ cd webshop
$ rails generate scaffold User name email
  [...]
$ rails db:migrate
  [...]

For the user model, create a minimal validation in app/models/user.rb so that you can be sure that each user has a name and a syntactically correct e-mail address (see Listing 11-1).

class User < ApplicationRecord ...

Get Learn Rails 5.2: Accelerated Web Development with Ruby on Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.