Posts

Showing posts with the label ruby best practices

Ruby on Rails: Understanding, Optimizing, and Mastering Database Queries with Preloading, Eager Loading, Includes, and Joins

Hi, This is  Shubham Mishra  from India,  this is the part of  Ruby on Rails  exploration journey.  In this post we will discuss about the ruby's some special concepts and I am sure you will get excited to make your hands dirty with those code, so why to wait let's get started... In this article we will explore best practices to avoid N+1 query issue in ruby on rails and also best practices to make database query optimised. And we also need to keep below stuffs in mind while doing the code review of our peer. Ruby on Rails offers a number of methods for preloading related items in order to get around the N+1 query problem. When the application does his N+1 database queries, the N+1 query problem arises. where N represents the total number of records found. Serious performance problems may result from this, especially when working with huge datasets. Using eager loading, which preloads related objects when the database is requested, is one way to deal wi...

Ruby best secure code approaches

Hi, This is  Shubham Mishra  from India,  this is the part of  Ruby on Rails  exploration journey.  In this post we will discuss about the ruby's some special concepts and I am sure you will get excited to make your hands dirty with those code, so why to wait let's get started... It's crucial for software engineers to build secure code in addition to functional code. In order to ensure the security of our apps, we will discuss several security best practises in this blog. 1. Avoid SQL Injection One of the most common security vulnerabilities in web applications is SQL injection. To avoid SQL injection in Ruby, use the built-in parameter binding mechanism provided by your database driver. This ensures that user input is properly escaped and prevents malicious SQL statements from being executed. In above snippet rather than block A, use block B approach, This way, the name parameter is properly escaped and cannot be used to inject malicious SQL code. 2...