Recent posts

  • How to start rails console on


    fly ssh console
    Connecting to fdaa:0:xxxx:xxx:xxx:xxxx:xxxx:2... complete
    root@4xxxxxxxxxx8:/app# rails c
    -bash: rails: command not found
    read more
    rails fly
  • Error running '__rvm_make -j12'


    Error running '__rvm_make -j12',
    please read /Users/deepak/.rvm/log/1704350883_ruby-3.3.0/make.log
    read more
    rvm ruby
  • What's new in Rails 7.1


    Rails 7.1 Beta 1 is released on September 13, 2023.

    Rails 7.1 is released on October 5, 2023.

    Let’s see what is new in rails 7.1


    Rails will now auto generate docker related files in the application.


    Build and run your application using docker

    docker build -t app .
    docker volume create app-storage
    docker run --rm -it -v app-storage:/rails/storage -p 3000:3000 --env RAILS_MASTER_KEY=<your-config-master-key> app
    read more
    rails rails7-1
  • Error installing puma - Failed to build gem native extension


    Building native extensions. This could take a while...
    ERROR: Error installing puma:
    ERROR: Failed to build gem native extension.
    read more
    puma rubygems
  • How to get rid of bot accounts from Twitter timeline.

    Tired of the bot accounts showing up in the twitter replies section?

    There’s no direct way to block all the bot accounts as of 14th July 2023.

    But we will show you a way to get rid of the bot accounts to some extent.

    Let’s see how to do it:

    read more
    twitter bots
  • undefined method `exists?' for File:Class (NoMethodError)

    Recently we upgraded ruby to 3.2. We started getting the following error:

    /Users/deepak/.rvm/gems/ruby-3.2.2@my-project/gems/pundit-2.3.0/lib/generators/rspec/templates/policy_spec.rb:1:in `template':
    undefined method `exists?' for File:Class (NoMethodError)
    Did you mean?  exist?

    This is how we traced it and fixed it:

    read more
    ruby rubygems pundit
  • How to clear Twitter interests in bulk.

    Are you getting random tweets on your timeline?

    Or you clicked on a tweet and now you’re getting tweets related to the same topic and can’t get rid of it.

    Let’s see how to get rid of the interests:

    read more
    twitter javascript
  • Audio element autoplay issue on redirection with turbolinks.

    Background of the issue

    Recently, we were working on a feature where we wanted to autoplay the audio.

    So like a normal developer we did the following:

    <audio autoplay data-audio-target="audioElement">
      <source src="">

    Since this is a rails project and we have turbolinks on, we came across an interesting issue.

    Whenever we were navigating from the page with the audio element to any other page the audio from the previous page used to play.

    We tried to search the same and came across few issue in the turbolinks repository.

    We found few solutions but since we were using stimulus js we solved it with the following approach

    read more
    rails stimulusjs turbolinks
  • 5 Must have gems in Ruby on Rails development environment.

    I have been developing rails applications since 2014. I started my career with rails and since then I have worked on numerous rails projects.

    These are a few gems that I like to add to almost all of my projects (including the personal projects). These gems definitely increase productivity and make the developer’s life easier.

    These are my top 5 gems you should have in your development environment.

    read more
    ruby rubygems
  • A step by step guide to upgrade rails 4 application to rails 5

    Upgrading an application can be tedious if you don’t have good test coverage.

    This article covers the common issues you might face while upgrading the from rails 4 to 5.

    If you are upgrading to ruby 2.7 export RUBYOPT="-W0" to avoid getting your screen filled up with deprecations warnings

    export RUBYOPT="-W0"
    bundle exec rspec
    # OR use
    RUBYOPT="-W0" bundle exec rspec
    read more
    rails rails-upgrade
  • Elasticsearch::Model - Partial update with custom callbacks

    If you want to partially update the documents on Elasticsearch you can include Elasticsearch::Model::Callbacks module.

    You can also perform partial update with custom callbacks instead of indexing the whole document.

    Elasticsearch Version - 5.3

    Partially update a document

    There is update_document_attributes method in Elasticsearch::Model which is used for partial update but it’s not documented. You can still use the method to perform the partial update.

    read more
    ruby elasticsearch
  • Rails and TimeZone issue with query

    You must have faced timezone issue if you work with the application in different timezone. ActiveRecord does take care of the timezone while creating, updating or querying the records. The DateTime is converted to UTC before the query is executed.

    You will face issue if you are using raw queries or passing String instead of DateTime.

    read more
  • Elasticsearch::Model - Put Mapping

    The PUT mapping API allows you to add fields to an existing index. This method is available with Elasticsearch::Model but it’s not documented.

    Elasticsearch Version - 5.3

    Create a User model

    > rails g model user first_name:string last_name:string email:string phone_number:string
    invoke  active_record
      create    db/migrate/20180420162454_create_users.rb
      create    app/models/user.rb
    > rake db:migrate
    read more
    ruby elasticsearch
  • Generating migrations with proper commands

    Creating a table

    If the migration name is of the form “CreateXXX” and is followed by a list of column names and types then a migration creating the table XXX with the columns listed will be generated.

    $ rails g migration CreateUsers email:string:index


    class CreateUsers < ActiveRecord::Migration
      def change
        create_table :users do |t|
          t.string :email
        add_index :users, :email
    read more
    ruby rails
  • Include scoped associations

    Rails provide different ways to load associations from the database to avoid N + 1 query being fired. In this post, I will show you how to include associations with scope applied on them.

    I have two models User and Post with following associations:

    # app/models/user.rb
    class User < ActiveRecord::Base
      has_many :posts, dependent: :destroy
    # app/models/post.rb
    class Post < ActiveRecord::Base
      belongs_to :user
      scope :published, -> { where(published: true) }
    read more
    ruby rails