Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # environment.rb
- # Load the Rails application.
- require File.expand_path('../application', __FILE__)
- # Initialize the Rails application.
- Rails.application.initialize!
- ActionMailer::Base.smtp_settings = {
- user_name: 'your_sendgrid_username',
- password: 'your_sendgrid_password',
- domain: 'yourdomain.com',
- address: 'smtp.sendgrid.net',
- port: 587,
- authentication: :plain,
- enable_starttls_auto: true
- }
- class UserMailer < ApplicationMailer
- default from: 'notifications@example.com'
- def welcome_email(user)
- @user = user
- @url = 'http://example.com/login'
- mail(to: @user.email, subject: 'Welcome to My Awesome Site')
- end
- end
- class UsersController < ApplicationController
- def index
- @users = User.all
- end
- def new
- @user = User.new
- end
- def create
- @user = User.new(user_params)
- if @user.save
- UserMailer.welcome_email(@user).deliver
- session[:current_user_id] = @user.token
- redirect_to root_path
- else
- render :new
- end
- end
- private
- def user_params
- params.require(:user).permit(:email, :password, :first_name, :last_name, :login)
- end
- end
- doctype html
- html
- head
- meta content='text/html; charset=UTF-8' http-equiv='Content-Type'
- body
- Welcome to example.com,
- = @user.name
- p
- You have successfully signed up to example.com,
- your username is:
- = @user.login
- p
- To login to the site, just follow this link: = @url
- p
- Thanks for joining and have a great day!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement