Handling Timezone in MySQL queries in a Rails application

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

Deployment of Rails App on DigitalOcean with Capistrano, Nginx and Passenger - Part 3

In previous articles, we have seen how to setup droplet on DO and installation of Nginx with the passenger. Capistrano provides you advanced tools to deploy your applications on the web server. It also allows you to perform pre and post-deployment steps such as restarting a web server, running migrations, deleting cache, etc. You can also write your custom task to run while deployment. Capistrano takes your code from version control such as Git and copies it onto your server via SSH. In this article, we will, be covering basic steps to deploy your application on a single server from

JQuery .closest() and .find() Selectors

The .closest() and .find() are very handy methods in JQuery. These 2 selectors are useful when you want to find corresponding elements where the event has triggered. .closest(): This selector traverses up the DOM till it finds the matching element for the supplied selector. .find(): This element traverses down the DOM along descendants of supplied DOM element. Let's take a look at one example of how to use these 2 selectors together. <form action="/posts/456/attachments"> <strong>Upload file:</strong> <br> <input type="file" name="

Deployment of Rails App on DigitalOcean with Capistrano, Nginx and Passenger - Part 2

In the previous article, we have seen how to configure DigitalOcean Droplet. Now let's proceed further to set up our application repository and Ngnix with Phusion Passenger on the DigitalOcean droplet. 1. Install RVM and Ruby We will install ruby using Ruby Version Manager(RVM) as it gives more flexibility to manage multiple ruby versions on the same system over rbenv, chruby, etc. Import RVM GPG key, before installing RVM: gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 Then, install RVM: curl -sSL https://get.rvm.io | bash -s stable Load RVM script and run requirement command to manage the

Deployment of Rails App on DigitalOcean with Capistrano, Nginx and Passenger - Part 1

Nginx is a lightweight, high-performance web server. Passenger used with Nginx gives us many advantages. It automatically serves static assets from the public subdirectory to improve performance. Capistrano is used to automate deployment process to your remote server. Using Capistrano, you can deploy your web application on many servers simultaneously in sequence or as a rolling set. In this article, we will see basic steps that need to be followed to configure your DigitalOcean Ubuntu Droplet. Prerequisites: Ubuntu 16.04 x64 Droplet Working Rails app hosted in a remote git repository that's ready to be deployed Initial setup for the

JQuery Performance Tip - Native functions instead of their Helper Counterparts

Recently, I had come across a situation where I had to make 2 ajax calls sequentially, i.e. fetch address from GeoLocation API and send it to Fedex API for fetching the transit time. For this, I needed to convert the address from GeoLocation in particular format using loop to send it to Fedex. Initially, I used '$.each()' method of jquery on an address array to convert it in desired format. This is common approach that we follow and it took 1.12ms for the processing. I wanted to reduce this processing time. After a bit of research,

ActiveRecord Attributes API

ActiveRecord Attributes And Defaults - The Old Way Imagine that you are in a vacation rental industry and you are adding a new model for handling reservations for rentals, let’s call it Reservation. To keep it simple for the purpose of this example, let’s assume that we need start_date and end_date date fields for handling the duration of the reservations and price field, which is pretty useful unless you are developing an app for a charity organization ;). Let’s say we want to provide some defaults for the start_date and end_date attributes to be

Rspec guideline with Ruby

Guideline for writing Good specs