O'Reilly logo

Learn Rails 5.2: Accelerated Web Development with Ruby on Rails by Stefan Wintermeyer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

© Stefan Wintermeyer 2018

Stefan Wintermeyer, Learn Rails 5.2, https://doi.org/10.1007/978-1-4842-3489-1_11

11. Action Mailer

Stefan Wintermeyer

(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).

Listing 11-1 app/models/user.rb ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required