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"] CSV.open(file, 'w', write_headers: true, headers: headers) do |writer| products.each do |product| writer << [product.id, product.name, 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