1

in my rails application i have registration_controller, session_controller and confirmation_controller.now i want to send the email after user signing up.so how can i do this.if anyone know the process please kindly share your code so that i can understand,how mailer work.please help me.

registration_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController



  private

  def respond_with(resource, options={})
     if resource.persisted?
       render json: {
          status: { code: 200, message: 'Signed up successfully', data: resource }
       }, status: :ok
       else
        render json: {
          status: { message: 'user could not be created successfull',
            errors: resource.errors.full_messages }, status: :unprocessable_entity
        }
     end
  end

end
session_controller.rb

class Users::SessionsController < Devise::SessionsController
  respond_to :json

  private

  
   def respond_with(resource, options={})
     if resource.persisted?
      render json: {
       status: { code: 200, message: "Signed in successfully",
         data: current_user }
     },status: :ok
       else
         render json: {
           status: 401,
           message: "check your credential"
         }
     end
   end

   def respond_to_on_destroy
     jwt_payload = JWT.decode(request.headers['Authorization'].split(' ')[1], Rails.application.credentials.fetch(:secret_key_base)).first
    current_user =  User.find(jwt_payload['sub'])
     if current_user
       render json: {
         status: 200,
         message: "Signed out successfully"
       }, status: :ok
       else
         render json: {
           status: 401,
           message: "user has no active sessaion"
         }, status: :unauthorized
     end
   end
end

routes.rb

Rails.application.routes.draw do
  resources :books
  # resources :userforms
  get 'book/', to: 'books#showImages';
  devise_for :users, controllers: {
    sessions: 'users/sessions',
    registrations: 'users/registrations',
    confirmations: 'users/confirmations',
  }
  # resources :userforms
  resources :userforms, only: [:show ,:index,:create,:showUsers]

  get 'userform/', to: 'userforms#showUsers';

end

above are my registrationcontroller, session_controller and my routes.rb.so now i want to send email how can i do this.

Thanks in advance.

0 Answers0