Rails is a MVC web application framework which supports building complex websites without writing any APIs. But, client side libraries are evolving at brisk pace with wide-spread use of React JS, AngularJS, VuJS etc. Thus, building API endpoints is a very important tasks these days.»
Rails Date, DateTime, Time, TimeWithZone class objects
could be compared using less than,
greater than signs.
to compare objects
of these datetime classes.
When coding in Ruby, we tend to make typo errors. This can take up time if not quickly identified. did_you_mean spellchecker gem helps detect such errors and also presents suggestions that can resolve typo errors.»
To parse natural language datetime string in Ruby,
we can use gem
Chronic is a
date parser in Ruby.
This comes very handy,
if we want to parse natural language datetime input
from user to
CompareWithRange core extension adds support
Range as an argument
Ruby already has support for these three methods,
but ruby does not support Range value as an argument.
This change is targetted to release and deprecate
with Rails 6.1.
has been released recently.
method was introduced with the release.
This is equivalent to
The feature returns random bytes
the length argument passed to it.
Before action callback in Rails has support to add conditions like if and unless. The callback is executed only if the conditions evaluate to true. But, skip_before_action callback does not support conditionals. In this article we will learn how to skip certain action based on some condition.»
Sometimes we need to parse a date string in UTC timezone in Ruby. Time.parse considers system time zone whereas we might want to parse time in UTC or some other custom timzone. This article helps parse time in UTC or any other zone.»
Rails ActiveSupport Enumerable adds index_with method. This method allows creating hash with a value from block passed or default value. This is useful when we want to create a hash and value needs to be generated with some custom logic.»
Sometimes we need to have a request be processed in a particular timezone in Rails. To set a timezone per request in Rails, we can have an around filter that sets timezone, runs the requests and then resets timezone to what it was before the request.»
Rails redirects route not found requests to 404.html page. Sometimes, we need to redirect to 404 not found page from a controller action. This can be done by rendering 404.html page or raising ActionController::RoutingError error.»
Time.zone in a Rails application changes time zone globally.
Time.now is used in any other request,
it uses whatever Time.zone is set to earlier.
To avoid Time.zone issues, do not set
in_time_zone method to get time in desired zone.
Before Rails 5.1, secrets management was a hassle.
sekrets were being used
manage secrets in Rails applications.
Rails 5.1 released secrets management feature based on sekrets gem.
This article will explain how to manage application secrets with Rails 5.1 applications.
Writing subqueries can be a tedious job, when working with Rails ActiveRecord. Rails ActiveRecord can handle subqueries. Subqueries can be written by passing ActiveRecord Relation in where clause. This article discusses how to write subqueries with ActiveRecord in Rails.»
Missing indexes on database tables causes performance issues.
gem helps finding out missing indexes on database table in Rails code.
lol_dba performs static analysis of the code to find out missing indexes.
We will take a look at how to use
lol_dba to find out indexes.
lol_dba also helps creating a migration to add the requred indices.