Alternative ways to include NULL values in the results while using SQL negation commands(!= or NOT IN) with Rails

In the previous article, we went through How NOT IN works with NULL values. We also learned how we can overcome this restriction. In this article, we will look at alternative ways to handle NULL values with SQL functions. So basically when we use != or NOT IN in query, it ignores the records with NULL values for fields. User.where("state != ?", 'active') SELECT * FROM users WHERE state != 'active' OR User.where("state NOT IN (?)", ['active']) SELECT * FROM users WHERE state NOT IN ('active') The above queries will consider records with state having a NOT NULL value,

How we improved the process of Code and Functional Reviews

Code reviews are important to deliver quality and well-crafted software. But what if the PR lingers in the review queue waiting for reviewers for an extended period? We faced a similar issue in one of our team where few stories were delayed due to pending reviews from the members. In this article, I would like to share about how we improved the Code and Functional Review process resulting in high quality and happiness. *This process was identified and implemented for one of the projects and every project could have minor customization based on the nature and requirement of the project.

How NOT IN works with NULL values.

Recently I faced one scenario with NULL value with NOT IN, I have added the details here about what I learnt. suppose we have two table Category and Product Category id | name -------- 1 | Category 1 2 | Category 2 3 | Category 3 4 | Category 4 Product id | name | category_id ----------------------------- 1 | Product 1 | 1 2 | Product 2 | 2 3 | Product 3 | 2 4 | Product 4 | 3 5 | Product 5 | 4 6 | Product 6 | NULL Scenario :- *I just want to retrieve all the Products excluding Category 1 and Category 3 so I wrote following query :- Product.joins(:category)

Export data to CSV file from Rails console

In one of my project I would like to dump and export some information into a csv file. I have produced an easy script to do that. require 'csv' file = "#{Rails.root}/public/user_data.csv" products = Product.order(:first_name) headers = ["Product ID", "Name", "Price", "Description"], 'w', write_headers: true, headers: headers) do |writer| products.each do |product| writer << [,, product.price, product.description] end end Here is what the above snippet does: Require the CSV library, since we'll be manipulating

Caching with Redis

What is Redis? Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. Why should we use Redis? By default, Rails uses the database to cache internal application data which can be expensive to generate (menu trees, views, filter results, etc), and to keep cached page contents. Since the database also handles many queries for normal page requests, it can create a bottleneck and increase load-times. Redis provides an alternative caching backend for Rails, taking that work off the database, which is vital for scaling to a larger number of logged-in

Attaching images using Attachinary and Cloudinary

A] Cloudinary: Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline. It is used to easily upload images to the cloud. It automatically performs smart image resizing, cropping and conversion without installing any complex software. Also, integration of Facebook or Twitter profile image extraction in a snap,that too in any dimension and style to match your website’s graphics requirements. Add following line to your Gemfile: gem 'cloudinary' Add following line to config/cloudinary.yml development: api_key: //enter api key api_secret: //enter api secret cloud_name: //enter cloud name