Create new rails application for API using below command: rails new article-app --api
creating new application using --api this will not generating any middleware such as view, helper, asserts. And ApplicationController inherit from ActionController::API instead of ActionController::Base
Steps:
- rails g model user email password_digest confirmation_token confirmed_at confirmation_sent_at
- rails db:migrate
- gem 'bcrypt'
- gem 'letter_opener'
- rails g job send_confirmation_instruction
- rails generate mailer UserMailer
- gem 'sidekiq'
- rails g controller registrations
- rails g controller sessions
- gem 'jwt'
- rails g model article title description user:references
- rails g controller articles
Open letter is used for the set delivery method into development.rb when email is being sent. Add below configuration into config/environments/development.rb
config.action_mailer.delivery_method = :letter_opener config.action_mailer.perform_deliveries = true
Create a job to send an email confirmation. I used sidekiq as a background job to send emails. gem 'sidekiq' run bundle install. Set your queuing backend after installing the background job. add queue_adapter into config/application.rb config.active_job.queue_adapter = :sidekiq
I've been using action mailer to deliver emails. rails generate mailer UserMailer
Now UserMailer has a confirmation_notify method. And under app/views/user_mailer/, build confirmation notify.html.erb
Setup to local:
- clone it in local
- bundle install
- rails db:create db:migrate Ready Go !!!