<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Deepak Chauhan</title>
    <description>The latest articles on DEV Community by Deepak Chauhan (@rishudc119).</description>
    <link>https://dev.to/rishudc119</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F281727%2Fd509678c-7830-4b82-9836-1302e98108b9.jpg</url>
      <title>DEV Community: Deepak Chauhan</title>
      <link>https://dev.to/rishudc119</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rishudc119"/>
    <language>en</language>
    <item>
      <title>Preventing Concurrent Migrations in a Distributed Environment</title>
      <dc:creator>Deepak Chauhan</dc:creator>
      <pubDate>Thu, 25 May 2023 16:59:41 +0000</pubDate>
      <link>https://dev.to/rishudc119/preventing-concurrent-migrations-in-a-distributed-environment-5c6m</link>
      <guid>https://dev.to/rishudc119/preventing-concurrent-migrations-in-a-distributed-environment-5c6m</guid>
      <description>&lt;h3&gt;
  
  
  Introduction:
&lt;/h3&gt;

&lt;p&gt;In a distributed environment, where multiple apps share a single database, running migrations simultaneously can lead to conflicts and deployment failures. In this article, we'll explore a solution to prevent concurrent migrations and ensure smooth deployments. We'll discuss the issue, the approach used, and the code changes implemented to tackle this problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem:
&lt;/h3&gt;

&lt;p&gt;When running migrations in Rails, they are meant to run sequentially based on their timestamps. However, in a distributed environment like Heroku, multiple apps can trigger migrations simultaneously, causing conflicts and errors. This occurs when one app tries to run a migration while another migration is already in progress, resulting in an ActiveRecord::ConcurrentMigrationError exception.&lt;/p&gt;

&lt;h3&gt;
  
  
  Approach:
&lt;/h3&gt;

&lt;p&gt;To address this issue, we'll use a combination of advisory locks and environment variables to control the execution of migrations during deployment. The basic idea is to allow only one app to run migrations while the others skip them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Implementation:
&lt;/h3&gt;

&lt;p&gt;Let's walk through the code changes needed to implement this solution.&lt;/p&gt;

&lt;p&gt;Step 1: Create a release-tasks.sh Script&lt;br&gt;
We'll start by creating a shell script called release-tasks.sh in the project's root directory. This script will handle the execution of migrations during the release phase.&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/bin/bash
set -e

if [ "$RUN_MIGRATIONS" = "true" ]; then
  echo "Running migrations"
  bundle exec rake db:migrate
else
  echo "Skipping migrations"
fi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script checks the value of the RUN_MIGRATIONS environment variable. If it is set to "true," the script runs the migrations using bundle exec rake db:migrate. Otherwise, it skips the migrations.&lt;/p&gt;

&lt;p&gt;Step 2: Grant Execution Permissions to the Script&lt;br&gt;
To allow execution of the release-tasks.sh script, we need to grant it execution permissions. Run the following command:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;chmod +x release-tasks.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 3: Update the Procfile&lt;br&gt;
In the project's Procfile, we need to modify the release command to use our custom script. Open the Procfile and update the line as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;release: ./release-tasks.sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This change ensures that our release-tasks.sh script is executed during the release phase.&lt;/p&gt;

&lt;p&gt;Step 4: Set Environment Variables for Each App&lt;br&gt;
In Heroku, go to each app's settings and set the &lt;code&gt;RUN_MIGRATIONS&lt;/code&gt; environment variable. For the app that should run migrations, set &lt;code&gt;RUN_MIGRATIONS&lt;/code&gt; to "true". For the other apps that should skip migrations, either leave it unset or set it to any other value.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;By implementing this solution, we have effectively prevented concurrent migrations in our distributed environment. By using advisory locks and environment variables, we ensure that only one app runs migrations while others skip them during deployment. This approach promotes a more stable and error-free deployment process.&lt;/p&gt;

&lt;p&gt;Remember to test this solution thoroughly in a non-production environment before applying it to your live applications. It's crucial to consider the specific requirements and constraints of your own setup.&lt;/p&gt;

&lt;p&gt;I hope this article helps you in handling concurrent migrations in your distributed environment. Feel free to reach out if you have any questions or need further assistance.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>rails</category>
      <category>heroku</category>
      <category>concurrentmigrations</category>
      <category>deployment</category>
    </item>
    <item>
      <title>Automating Git Commit Messages with OpenAI's GPT-3: A Step-by-Step Guide</title>
      <dc:creator>Deepak Chauhan</dc:creator>
      <pubDate>Mon, 17 Apr 2023 05:44:20 +0000</pubDate>
      <link>https://dev.to/rishudc119/automating-git-commit-messages-with-openais-gpt-3-a-step-by-step-guide-1e77</link>
      <guid>https://dev.to/rishudc119/automating-git-commit-messages-with-openais-gpt-3-a-step-by-step-guide-1e77</guid>
      <description>&lt;p&gt;Automating Git commit messages with OpenAI's GPT-3&lt;/p&gt;

&lt;p&gt;Have you ever struggled to come up with a good commit message for your changes? Or have you found yourself writing the same type of commit message over and over again? With OpenAI's GPT-3 language model, you can now automate the process of generating commit messages for your changes.&lt;/p&gt;

&lt;p&gt;This blog post will guide you through a simple Python script that uses OpenAI's GPT-3 to generate commit messages based on the changes made to your code.&lt;/p&gt;

&lt;p&gt;GitHub repo&lt;/p&gt;

&lt;p&gt;The code for this blog post can be found on GitHub at &lt;a href="https://github.com/Dmoment/gpt-commit-message-helper"&gt;gpt-commit-message-helper&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The script is written in Python and uses the OpenAI API to generate commit messages. Before using the script, you will need to set up an OpenAI API key and install the openai Python library.&lt;/p&gt;

&lt;p&gt;Overview of the script&lt;/p&gt;

&lt;p&gt;The script works by generating a summary of the changes made to each file, and then using those summaries as prompts for the OpenAI API. The API generates a commit message based on the prompts, which is then returned to the script.&lt;/p&gt;

&lt;p&gt;Here's a high-level overview of the script:&lt;/p&gt;

&lt;p&gt;Get the list of files that have been changed (using Git).&lt;br&gt;
For each file, generate a summary of the changes made.&lt;br&gt;
Use the summaries as prompts for the OpenAI API to generate a commit message.&lt;br&gt;
Print the suggested commit message and prompt the user to approve it or enter a custom one.&lt;br&gt;
Commit the changes using the selected commit message.&lt;br&gt;
Let's dive into the code.&lt;/p&gt;

&lt;p&gt;Importing the necessary libraries and setting up the OpenAI API key&lt;/p&gt;

&lt;p&gt;The first few lines of the script import the necessary libraries and set up the OpenAI API key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;openai&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="nn"&gt;subprocess&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;requests.exceptions&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;RequestException&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;openai.api_key = os.environ.get("OPENAI_API_KEY")&lt;br&gt;
The openai library is used to interact with the OpenAI API. The os, sys, and subprocess libraries are used to interact with the operating system and Git. The RequestException class is imported from the requests library to handle errors when making API requests.&lt;/p&gt;

&lt;p&gt;The OpenAI API key is loaded from an environment variable, which should be set up before running the script.&lt;/p&gt;

&lt;p&gt;Setting up default values for the OpenAI API parameters&lt;/p&gt;

&lt;p&gt;Next, the script sets up default values for the OpenAI API parameters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;openai_engine&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OPENAI_ENGINE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"text-davinci-002"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;openai_max_tokens&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OPENAI_MAX_TOKENS"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"60"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;openai_temperature&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OPENAI_TEMPERATURE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"0.7"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="n"&gt;openai_stop&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;getenv&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"OPENAI_STOP"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These parameters control how the OpenAI API generates the commit message. The openai_engine parameter selects which OpenAI model to use. The openai_max_tokens parameter controls how many tokens (words or punctuation) are generated in the message. The openai_temperature parameter controls the "creativity" of the message. The openai_stop parameter can be used to add custom stop words that will cause the API to stop generating text.&lt;/p&gt;

&lt;p&gt;Generating a summary of the changes made to a file&lt;/p&gt;

&lt;p&gt;The generate_summary function takes a file path as input and generates a summary of the changes made to the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;generate_summary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Get git diff of the file
&lt;/span&gt;    &lt;span class="n"&gt;output&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;subprocess&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;run&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s"&gt;'git'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'diff'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;'--cached'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;file_path&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;capture_output&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="c1"&gt;# Extract added/modified/deleted lines from git diff
&lt;/span&gt;    &lt;span class="n"&gt;added_lines&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>git</category>
      <category>chatgpt</category>
      <category>python</category>
    </item>
    <item>
      <title>Devise and SendGrid integration into rails 6</title>
      <dc:creator>Deepak Chauhan</dc:creator>
      <pubDate>Thu, 19 Nov 2020 16:30:54 +0000</pubDate>
      <link>https://dev.to/rishudc119/devise-and-sendgrid-integration-into-rails-6-4fpm</link>
      <guid>https://dev.to/rishudc119/devise-and-sendgrid-integration-into-rails-6-4fpm</guid>
      <description>&lt;p&gt;Devise is a flexible production-ready authentication system supported in rails. The authentication system basically consists of three functionalities i.e. Signup, Login, and Logout. Further, in Signup, the password has to be a hashed password rather than a normal string and a confirmation link has to be sent on the registered email id for authenticating the user. In Login, a forget password functionality has to be there for recovery of password, and remember me functionality has to be there for saving credentials of the user in browser cookies for providing auto-filled credentials.&lt;/p&gt;

&lt;p&gt;Instead of coding all these functionalities from scratch, use Devise. It is pre-equipped with all these functionalities and all of it can be accomplished by just installing the Devise gem. Devise is used extensively with so many functionalities that can be customized but in this article, I will only write about authenticating the registered user through a verification link. After registration, a verifying link has to be sent on the registered email id of the user On clicking it the user can verify himself.&lt;/p&gt;

&lt;p&gt;HOW TO ACHIEVE THIS?&lt;/p&gt;

&lt;p&gt;Well, we know that all these email operations are performed by the SMTP(Simple Mail Transfer Protocol) server. However, to set up an SMTP server for a beginner is quite back-breaking. Instead, we can use Sendgrid. SendGrid is a cloud-based SMTP provider that allows you to send email without having to maintain email servers. SendGrid manages all of the technical details and left you with just reaping the benefits of someone else’s effort.&lt;/p&gt;

&lt;p&gt;LET’S CODE THIS&lt;/p&gt;

&lt;p&gt;First, let’s include Devise gem and bundle install it in our gemfile.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem 'devise'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;After bundle install. You need to run the generator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails generate devise:install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The generator will install an initializer which describes ALL of Devise’s configuration options. By default, there are no views and models. You have to generate them. Let’s now generate a model User&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails generate devise User&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;You can also generate the corresponding Devise views.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails generate devise:views users
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can find a migration file that has been generated. Pull up that migration file and uncomment the 4 lines under confirmable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;t.string :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string :unconfirmed_email
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pull up the user.rb model file under app/models and in the line for devise, add in a:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:confirmable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;, after :registerable, entry Run your migration now to create the users table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rails db:migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Devise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_action&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;before_action :authenticate_user!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, Let’s hop onto sending email in production&lt;/p&gt;

&lt;p&gt;for beginners, we are using Heroku as a production server. First, add your credit card details to your Heroku account. (Don’t worry this will not cost you a penny). Then enter in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku addons:create sendgrid:starter
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will add a SendGrid add-on to your deployed Heroku project. You can log in to your SendGrid account through this addon and in your SendGrid account menu you have to create an API key. After creating an API key, Now, we have to set the SendGrid API key credentials you created for Heroku.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;heroku config:set SENDGRID_USERNAME=apikey
heroku config:set SENDGRID_PASSWORD=enterintheapikey
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the SENDGRID_PASSWORD you have to enter the API key that you have created from SendGrid above Rails provides you to securely store your API credentials in your credentials.yml file. All the data inside this file is encrypted so security is ensured. The encrypted credentials.yml.enc file will be decrypted in production, using a key stored in the RAILS_MASTER_KEYenvironment variable For people using the VS Code as an editor. You can edit the credentials.yml file by enabling the edit mode as below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;EDITOR='code --wait' rails credentials:edit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After issuing this command you can store your Sendgrid credentials in this file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; sendgrid:
   user_name: apikey
   password: Your API key
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under config/environment/production.rb file add in the following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ActionMailer::Base.smtp_settings = {
      :address =&amp;gt; 'smtp.sendgrid.net',
      :port =&amp;gt; '587',
      :authentication =&amp;gt; :plain,
      :user_name =&amp;gt; Rails.application.credentials.dig(:user_name),
      :password =&amp;gt; Rails.application.credentials.dig(:password),
      :domain =&amp;gt; 'heroku.com',
      :enable_starttls_auto =&amp;gt; true
    }
    config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options ={:host =&amp;gt; 'yourherokuapp.herokuapp.com', :protocol =&amp;gt; 'https'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now update the development.rb file under config/environments folder and add the following lines&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; ActionMailer::Base.smtp_settings = {
      :address =&amp;gt; 'smtp.sendgrid.net',
      :port =&amp;gt; '587',
      :authentication =&amp;gt; :plain,
      :user_name =&amp;gt; Rails.application.credentials.dig(:user_name),
      :password =&amp;gt; Rails.application.credentials.dig(:password),
      :domain =&amp;gt; 'heroku.com',
      :enable_starttls_auto =&amp;gt; true
    }

    config.action_mailer.delivery_method = :smtp
    config.action_mailer.default_url_options ={:host =&amp;gt; 'http://localhost:3000'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This setup configuration is both for the production and development environment.&lt;br&gt;
Now it is all set up. When you sign up now SendGrid will send a verification link to the registered email of the user. The confirmation link will look something like this.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwpbpsfwroaecb1u96hyq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwpbpsfwroaecb1u96hyq.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sendgrid verification link&lt;/p&gt;

&lt;p&gt;If you want to redirect the user to a specific URL after they clicked the link in the confirmation email, override the after_confirmation_path_for in your confirmations_controller:&lt;/p&gt;

&lt;p&gt;Create a new confirmations_controller.rb in app/controllers directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ConfirmationsController &amp;lt; Devise::ConfirmationsController
  private
  def after_confirmation_path_for(resource_name, resource)
    sign_in(resource) # In case you want to sign in the user
    your_new_after_confirmation_path
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In config/routes.rb, add this line so that Devise will use your custom ConfirmationsController. This assumes Devise operates on the users table (you may edit to match yours).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;devise_for :users, controllers: { confirmations: 'confirmations' }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart the webserver, and you should have it.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>devops</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
