Sometimes dealing with DB processes in a Rails application consume a lot of time. Often there are a bunch of small and simple DB queries that go endless. For example, bulk insertions or bulk updates in tables. Dividing it into various background jobs is an idle solution. In a few scenarios, we can't prefer background jobs e.g. the change you apply, makes the existing data invalid. In this article, we will see how to complete a large set of DB queries under minutes which would otherwise take hours if not optimized. It's a better practice to create a rake
To enhance the security of a web application having a user authentication workflow, we use a security method called 2FA. It is also known as Two Factor Authentication(type of Multi-Factor Authentication). In this blog post, we will see how to implement email-based 2FA in ActiveAdmin auth of a Ruby on Rails application. In the email-based 2FA approach, when logging in with an email and password, an OTP will be sent on a registered email address. Upon entering the OTP, it will successfully authenticate and the session will be started. Also, we will see the following additional functionality and customizations
Writing unit tests is more of an art than a skill, and understanding what to test for comes with experience and/or mistakes. We look for the percentage of test coverage for examining the health of an application. However, the "coverage percentage" might be misused or overlooked. In particular, it falls victim to Goodhart’s law, which says: “When a measure becomes a target, it ceases to be a good measure”. Whenever we start writing test cases for the sake of improving the code coverage, we miss the whole point of testing and rather introduce Tautological Tests - poorly designed
Handling timezones in Rails applicationsIn the Rails application, we may have two different timezones. Application timezoneDatabase timezoneIn most of the cases database timezone is set to UTC, but application timezone could be different from database timezone. How to set application timezone?Set timezone at the application levelWe can set config.time_zone configuration in config/application.rb file. ActiveRecord fetches UTC from the database and converts it to the timezone specified in config.time_zone. Refer this article in case you need help with setting up timezone at application level. 2. Set the timezone based on the one specified by
While performing concurrent operations, a database must ensure data integrity. ACID compliant relational database ensures this data integrity through its locking mechanism. ACID = Atomicity, Consistency, Isolation, Durability Locks can be at the database, table, page, or row level. Here is a beginner's guide to database locking in PostgreSQL. In this article, let's see how Rails provides a mechanism for optimistic locking on ActiveRecord models. However, before we proceed, let us first understand the basics of optimistic and pessimistic locking. What is optimistic locking? Let's take an example of two admin users, Mohan and Ritesh, managing the product inventory in their
This blog illustrates how we can easily setup a ruby on rails application with ReactJs as a front-end framework
For the past few months at Kiprosh, we've done versions upgrade of multiple mid to large scale Ruby on Rails applications. One of them was running Rails version 3.2.22. That's where we found out that, we need to make a lot of changes in our codebase to run our application on version 4.0. Hence, we thought to write this blog post to share our insights and recommended strategies for upgrading such mid to large Rails applications. upgrading Ruby on RailsRails guides provide us a brief information on how to upgrade the Rails app, but we need to
Recently, our organization planned to migrate an internal application web API to Nodejs web API. We have everything to work on node app, but we were lacking a console where we can run queries and examine results to implement them in our controller or vice-versa. fig 1. Nodejs consoleWhat we have in Ruby on Rails frameworkrails_app $ rails c irb(main):005:0> User.first User Load (0.7ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1 => #<User id: 1, email: "firstname.lastname@example.org"
Emoji has become an essential part of communication in our digital lives. Hence, as developers, our applications should provide first-class support to them. In this blog post, we will explore how to store Emoji's in MySQL database. In one of our internal Ruby on Rails web application using MySQL database, we were facing an issue whenever a user tried to insert an emoji in the text of an article. The "save" functionality in UI ran infinitely (ajax) and logs were reporting following errors: ActiveRecord::StatementInvalid (Mysql2::Error: Incorrect string value: '\xF0\x9F\x98\x8A ...' for column 'content' at
As a tech organisation, we always strive to find suitable talent for available positions, and then move them quickly through the application funnel, from sourcing to hiring. The goal is to onboard a potential candidate as fast as possible. In this endeavor, we decided to automate our recruitment processes so that the overall time to screen, interview and to release an offer is relatively faster. Background Interested candidates apply on our website through careers page. We have a referral program for our associates so it also resulted in wider interest. We also receive direct applications through email on careers@kiprosh.