Securing Ruby on Rails Applications: Part 6 (Use Two-Factor Authentication (2FA))

In an increasingly digital world, ensuring the security of user accounts has become a critical concern for web developers. One effective method to safeguard user data and prevent unauthorized access is through Two-Factor Authentication (2FA). This authentication process adds an extra layer of security by requiring users to provide two forms of identification before accessing their accounts. In this article, we will explore how to implement 2FA in a Ruby on Rails application, with code examples to guide you through the process.

Securing Ruby on Rails Applications: Part 5 (Sanitize User Input)

Ruby on Rails is a powerful web application framework that enables developers to build robust and scalable web applications. However, like any other web application, Rails applications are vulnerable to attacks if not properly secured. One of the most critical aspects of securing a Rails application is sanitizing user input.

Securing Ruby on Rails Applications: Part 4 (Use Secure Session Management)

Ruby on Rails is a powerful and popular web application framework that allows developers to build secure and scalable web applications. However, like any other web application, Rails applications are vulnerable to attacks if not properly secured. One of the most important aspects of securing a Rails application is secure session management.

Securing Ruby on Rails Applications: Part 3 (Use Strong Parameters)

Ruby on Rails is a popular web framework that is known for its security features. However, there are still many steps that developers need to take in order to ensure that their Rails applications are secure. One important step is to use strong parameters to protect against malicious input.

Securing Ruby on Rails Applications: Part 2 (Input Validation)

Input validation is an essential part of web application security, as it ensures that data entered by users is in the expected format and doesn’t contain any malicious content. In Ruby on Rails, input validation can be implemented using various methods and libraries. In this article, we’ll explore some of these techniques and provide code examples.

Understanding Ancestor Chains in Ruby

An ancestor chain in Ruby on Rails refers to the path of inheritance leading up to a given class or module. Understanding ancestor chains goes deeper into Ruby’s core functionality. By tracing the ancestor chain of a class or module, you can better understand its relationships to other parts of their application and to Ruby itself.

Securing Ruby on Rails Applications: Part 1 (Use Strong Authentication and Authorization Mechanisms)

Authorization is an essential aspect of web application security that ensures that only authorized users have access to certain resources or functionalities within the application. Ruby on Rails provides several mechanisms for implementing authorization, including role-based and attribute-based authorization. In this article, we will discuss how to implement authorization in Ruby on Rails, with code examples.

A Quick Guide to Basic Caching in Ruby on Rails

Caching is a useful method that can improve the performance of web applications. By caching frequently accessed data and pages it can make the application faster, can serve content more quickly resulting in a better user experience, and improve the scalability of the application by reducing the number of requests made to the database. In this blog post, we will discuss some commonly used caching methods in Ruby on Rails.

Boosting Your Rails Console With .irbrc

You’re likely familiar with the IRB (Interactive Ruby Shell) console, a powerful tool that enables you to quickly test and experiment with Ruby code. However, did you know that you can customize the IRB console by using a .irbrc file? This file is a Ruby script that executes every time a new IRB console is started. By using a .irbrc file, you can customize the IRB console, improve your productivity, and ensure consistency across your development environment.

Boosting Performance and Readability: ActiveSupport::ArrayInquirer vs. includes

ActiveSupport::ArrayInquirer is a handy utility class that allows you to easily work with arrays. It makes it easy to check whether an array includes a certain value without having to write complex code.

Rails routes table search

The Rails router handles incoming HTTP requests and maps them to the appropriate controller/action. Developers can define routes by adding them to routes.rb.

Ruby on Rails Log Levels: Examples and Best Practices

Logging is important in any software development project because it helps to understand how the application is behaving and identify issues when they occur. The errors of an application cannot all be treated in the same way, as they have different levels of importance. Depending on where the error occurs in your application, it can be fatal to a process or just a warning.

Rails default Dockerfile

Docker has become an industry standard. It allows developers to create, deploy, and run applications inside containers. In Rails 7.1, Dockerfiles are included by default. This makes it easier than ever to deploy Rails applications using Docker.

Showing All Headers in Action Mailer Previews

ActionMailer previews can now display all email headers. This allows developers to check all headers, when testing locally.

Using Signed Global IDs with Polymorphic Select Fields in Rails Forms

Polymorphic associations allow a single association to reference multiple models. In a polymorphic association, the association name is used to store the name of the associated model, and the _id and _type attributes are used to store the ID and type of the associated record. However, polymorphic associations can be challenging to work with when it comes to using select fields, especially when there are multiple types of associated models.

Using Date Ranges in Rails Queries

When working with dates in Rails, it’s common to want to find records that fall within a certain range of dates. For example, you might want to find all orders placed between two dates, or all events scheduled for a certain week.

Turbo Streams Duplicate Element When Appending/Prepending

In January, 2021 a bug was reported in Turbo that caused duplicate DOM elements. In this post we’ll explain the bug and how it was fixed.

ActiveRecord regroup method

ActiveRecord’s regroup method is a shorthand for using unscope to remove existing groups.

Rails counter available in collection partials

Rails makes a counter variable available within partials that are rendered with a collection. This variable follows the name of the collection. A @users collection has a counter called user_counter. The counter works like the index on an each loop. It counts the number of times a partial has been rendered. Let’s look at an example.

Exploring the syntax_suggest feature in Ruby 3.2

Ruby 3.2 introduces the new feature syntax_suggest, formerly known as the gem dead_end, now integrated into Ruby. Catch and fix syntax errors are now more robust helping you to find the position of errors such as missing extra parentheses, commas, superfluous ends, errors such as missing or extra curly braces related to string interpolation, and semicolons.

Deploying Rails with Render

Heroku recieved some negative press for the removal of it’s free tier. Render is a cheaper alternative that boasts many benefits over Heroku. We believe Heroku is still the quickest way to spin up a Rails app but Render is close behind and less than half the price.

How to use Enumerator::Product in Ruby 3.2

Ruby 3.2 brings a convenient new addition that enables combining elements from various arrays or enumerable objects with ease. Enumerator::Product, one of the most convenient new methods, can be especially useful when working with large data sets or when generating combinations for testing purposes.

Writing to DynamoDB via Rails models

ActiveRecord is a core part of Rails, an ORM layer that sits on top of relational databases like Postgres or MySQL. However, it doesn’t natively support DynamoDB. Recently, we worked on a project to migrate part of a Rails app to Lambda functions. We began the migration by adding logic for writing to DynamoDB. Here’s how we did it.

Scaling Ruby on Rails Applications: Techniques and Tools for Optimizing Performance - Part 5 (Monitoring and Logging)

As your Ruby on Rails application grows, it becomes important to monitor its performance and log its activities. This helps you identify and fix issues, and also gives you insights into how your application is being used. In this article, we will discuss how to implement monitoring and logging in Ruby on Rails, with code examples.