Deep dive into ActiveRecord .scoping method in Rails

In Rails, multiple scopes can be created and chained together. What if we wish to apply a specific scope to a group of queries? Consider the following scenario: we have Post and Comment models and we want to perform few operations on public posts. # app/models/post.rb class Post < ActiveRecord::Base scope :public, -> { where(private: false) } endLoading development environment (Rails 7.0.0.alpha2) 3.0.0 :001 > Post.public.update_all(body: 'public post') Post Update All (4.1ms) UPDATE "posts" SET "body" = ? WHERE "posts"."private" = ? [["body", "public post"], ["private", 0]] 3.0.0

Video Hosting Platforms for Mobile Apps - A comparative study!

There are ample video hosting platforms available on the internet. Choosing a video hosting platform is a critical decision as it should go hand in hand with your long-term hosting requirements, alongside taking utmost care of security breaches for copyrighted content. The video hosting platform that we have been using for one of our web apps is Wistia. Why did we choose Wistia for our Web App? Embeds seamlessly in any websiteEnsures data security through domain restrictionsProvides in-video formsCustomizable video controls, and much more.What's the challenge to use it in Mobile Apps? The challenge came in when we wanted

Rails 7 introduces partial_inserts config for ActiveRecord

Rails 7 adds the partial_inserts config to config.active_record that is used to control partial writes when creating a new record. config.active_record.partial_inserts is a boolean value and controls whether or not partial writes are used when creating new records (i.e. whether inserts only set attributes that are different from the default). Configuring config.active_record.partial_inserts In a newly created Rails 7.0 application, config.load_defaults 7.0 is set by default in application.rb. The default value of partial_inserts for config.load_defaults 7.0 is false and for

Custom Utility Types in TypeScript

TypeScript's type system makes it very easy to add types as per our requirements. But most of the time, we may need to perform some transformations on existing types to get resultant type as per our requirements instead of adding a new one. Some common type transformations may include: Extraction of types Exclusion/Inclusion of types Setting types to required/optional Utility Types provided by TypeScript help in performing such type transformations. Utility Types are built-in and globally accessible functions available in TypeScript. Under the hood, they make use of Generics extensively. Some frequently used Utility Types are as follows:

Rails 7 supports tracking of belongs_to association

One of the most convenient features of Rails is the ability to track attribute changes. Rails 7 is releasing soon and bringing in a lot of new features as a treat for developers. One of the many features that Rails 7 is introducing, is that we can also track the associated object. This Rails ActiveRecord specific PR has added two methods for tracking the changes for the belongs_to association. In this article, we will discuss these two new methods with the help of examples. 1. association_changed?The association_changed? method tells if a different associated object has been

Quick Guide: Integrating Widevine DRM In ExoPlayer For Android

Day by day OTT platforms are getting popular and along with that, it is increasing the fear of content security breaches. Ever amazed at How do these platforms secure streaming content from piracy or content leakage? How the content distributions are being controlled? Initially, I had all these doubts and after diving deep I got introduced to DRM. What is DRM? DRM stands for Digital Rights Management. It is a system that uses various licenses, keys and encryption techniques to protect the digital contents and also ensures that only an authorized user can decrypt the file with the help of

Invite email with Add to Calendar link using C#

Have you ever organized an event where many of the registered guests didn't attend the event? To ensure maximum turnaround in an event, an email with an AddToCalendar link can be beneficial as it will help to remind the attendees once they add it to their calendar. Let's see how we can generate and add this magical link in our emails. What you’ll need? An ICS (Internet Calendar Scheduling) FileAn MVC API to download the fileAn ICS File 👀 What is that? The ICS format is a universal calendar file format that all popular calendar applications, including Microsoft Outlook, Apple

Side effects of Active Record's new feature #invert_where in Rails 7

Rails 7 is introducing a new method invert_where that will invert all scope conditions. It allows us to invert an entire where clause instead of manually applying conditions. We can either chain invert_where to a scope or to a where condition. class Account scope :active, -> { where(active: true) } end Account.active.invert_where => "SELECT \"accounts\".* FROM \"accounts\" WHERE \"accounts\".\"active\" != 1"Account.where(active: true).invert_where => "SELECT \"accounts\".* FROM \"accounts\" WHERE \"accounts\".\"active\" != 1"What are the various side effects of using invert_where?1. The invert_where method inverts all the where

Active Record Encryption in Rails 7

If you're hosting your web server in a particular region, it might be necessary to comply with the GDPR norms of that region. Anonymizing and encrypting data becomes necessary in such situations. In this blog, we will discuss the attribute encryption that Rails 7 provides right out of the box. And we will also see the Deterministic & Non Deterministic approaches. (If you're using Rails version lesser than 7, check out our previous blog here on how to write a custom encryption framework.) ActiveRecord attribute encryption in Ruby on Rails for better securityIn this blog post, we will explore a

Statistics for Data Analysis with Kotlin

Statistics is the grammar of science. - Karl PearsonData is the new oil. Just type in "Data Science" inside the Google Trends search box, and you would believe it too. The interest over time for data science has taken a boost in the recent past, for reasons as obvious as the theory of evolution and the survival of the fittest! One blog even read that the job of a data scientist is the sexiest job of the 21st century! What comes to our minds whenever we talk about which programming language to pick for data science? Let us be honest,