Want to deploy rails application using kamal? I post tips and help topics on kamal.wiki.
Recent posts
-
How to downgrade the postgres addon version on Heroku.
We recently had to downgrade the version of the postgres addon on Heroku.
Our production was running on version
14
and our staging server was running on16
.We wanted to downgrade the staging server to version
14
to ensure that the versions are consistent across environments.This is how we did it.
read more -
How to start rails console on fly.io
Issue
read morefly ssh console Connecting to fdaa:0:xxxx:xxx:xxx:xxxx:xxxx:2... complete root@4xxxxxxxxxx8:/app# rails c -bash: rails: command not found
-
Error running '__rvm_make -j12'
Issue
read moreError running '__rvm_make -j12', please read /Users/deepak/.rvm/log/1704350883_ruby-3.3.0/make.log
-
What's new in Rails 7.1
Update:
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
Dockerfile
Rails will now auto generate docker related files in the application.
Dockerfile .dockerignore bin/docker-entrypoint
Build and run your application using docker
read moredocker 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
-
Error installing puma - Failed to build gem native extension
Issue
read moreBuilding native extensions. This could take a while... ERROR: Error installing puma: ERROR: Failed to build gem native extension.
-
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 -
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 -
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 -
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="https://www.xyz/..."> </audio>
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 -
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 -
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 warningsread moreexport RUBYOPT="-W0" bundle exec rspec # OR use RUBYOPT="-W0" bundle exec rspec
-
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
read moreupdate_document_attributes
method inElasticsearch::Model
which is used for partial update but it’s not documented. You can still use the method to perform the partial update. -
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
read moreString
instead ofDateTime
. -
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
read more> 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
-
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
db/migrate/20161201203703_create_users.rb
read moreclass CreateUsers < ActiveRecord::Migration def change create_table :users do |t| t.string :email end add_index :users, :email end end
-
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
andPost
with following associations:read more# app/models/user.rb class User < ActiveRecord::Base has_many :posts, dependent: :destroy end # app/models/post.rb class Post < ActiveRecord::Base belongs_to :user scope :published, -> { where(published: true) } end