1. #users_controller.rb
  2. class UsersController < ApplicationController
  3. before_action :set_user, only: [:show, :edit, :update, :destroy]
  4. def index
  5. @users = User.all
  6. end
  7. def show
  8. end
  9. def new
  10. @user = User.new
  11. end
  12. def edit
  13. end
  14. def create
  15. @user = User.new(user_params)
  16. respond_to do |format|
  17. if @user.save
  18. # Tell the UserMailer to send a welcome email after save
  19. UsersWorker.perform_at(2.minutes.from_now, @user)
  20. format.html { redirect_to root_path }
  21. format.json { render :show, status: :created, location: @user }
  22. else
  23. format.html { render :new }
  24. format.json { render json: @user.errors, status: :unprocessable_entity }
  25. end
  26. end
  27. end
  28. private
  29. def set_user
  30. @user = User.find(params[:id])
  31. end
  32. def user_params
  33. params.require(:user).permit(:name, :email, :note, :datetime)
  34. end
  35. end
  36. --------------------------------------------------------------------------
  37. #users_worker.rb
  38. class UsersWorker
  39. include Sidekiq::Worker
  40. def perform(user)
  41. UsersMailer.remind_email(@user).deliver_later
  42. end
  43. end
  44. --------------------------------------------------------------------------
  45. #users_mailer.rb
  46. class UsersMailer < ApplicationMailer
  47. default from: 'mailme'
  48. def remind_email(user)
  49. user = params[:user]
  50. mail(to: user.email, subject: "Sent from Mailme" )
  51. end
  52. end
Comments powered by Disqus