Time Helpers You Might Not Know

In Ruby on Rails, there are a number of time helpers that can be used to format and manipulate dates and times. We selected a few ones you might not know that can be used to make your code more readable and to provide a better user experience.

Precise URL Generation in Rails 7.1: Introducing path_params

Generating URLs within Rails applications can involve specifying parameters for various routes. Prior to Rails 7.1, dealing with scoped routes presented a minor challenge.

Simplify Code with ActiveSupport::StringInquirer

ActiveSupport::StringInquirer is a class provided by Rails’ ActiveSupport module that can streamline your code and make it more readable. Let’s dive into what ActiveSupport::StringInquirer is and how it can improve your Ruby on Rails development experience.

Quick Dive into Rails Concerns

In Ruby on Rails, concerns are modules that encapsulate common behaviors that can be shared among different model classes, controllers, or other components of the application. Concerns are used to avoid code repetition and maintain code modularity and organization.

Exploring Array Filtering: Beyond the Basics

Managing arrays is a common and essential task and when it comes to filtering elements based on specific criteria, a variety of methods are at our disposal. In this post, we’ll highlight some well-known methods along with others that might be less familiar in the Ruby world.

Rails 7.1's New Feature: Validate Option for Enums

Rails 7.1 introduces a significant enhancement to enum handling through the introduction of the :validate option.

Achieving Performance with Memoization

Building performant web applications is crucial so while Rails provides a robust framework, optimizing every piece of code is essential for a smooth user experience. This is where memoization comes in, a powerful technique to enhance your Rails app’s speed and efficiency. In scenarios with frequent database queries, it’s a straightforward yet impactful technique for boosting overall performance.

truncate_words vs. truncate: a comparison of the two methods

In Ruby on Rails, there are two main methods for truncating strings provided by Active Support: truncate_words and truncate. Both methods take a string as their argument, but they have different behaviors.

3 Lesser-Known Rails Features for More Readable Code

Improve your Rails code readability with these three useful features.

3 Lesser-Known Rails Features for Querying Databases

Improve your Rails app’s performance, flexibility, and data integrity with these three useful features.

A comprehensive guide to HTTP status codes in Ruby on Rails

The :status option provides flexibility in customizing the HTTP status code for a Rails response. By default, Rails generates a response with the appropriate HTTP status code, typically 200 OK for successful requests. However, the :status option allows developers to explicitly set the status code, enabling more granular control over response behavior. This option proves particularly useful when the default status code is not suitable for the response, such as returning a 404 Not Found status code for missing resources.

Why to use find_each instead of all in Ruby on Rails

In Ruby on Rails, there are two main methods for retrieving all records from a model: all and find_each. Both methods return an ActiveRecord::Relation, but they have different performance characteristics.

Computer Programming: Modern Day Magic?

A curious topic repeated across internet forums and social media is the uncanny parallel between programming and the occult.

When to use subject vs. let in RSpec

Subject allows you to define a common object to be tested in multiple examples in a single test case. It is typically used to represent an instance of the class that you are testing.

Rails 7.1: Generate tokens for specific purposes with generates_token_for

Rails 7.1 introduces a new method, generates_token_for, which allows you to generate tokens for specific purposes. These tokens can expire and can also embed record data. When using a token to fetch a record, the data from the token and the current data from the record will be compared. If the two do not match, the token will be treated as invalid.

A faster way to check the sign of a number in Ruby on Rails

Ruby has two methods for checking the sign of a number: positive? and negative?. These methods were introduced in Ruby 2.3, and they provide a more concise and readable way to check the sign of a number than using comparison operators.

Rails 7.1: Normalizes - A powerful new feature for data validation

In Rails 7.1, a new method has been added to the Active Record called normalizes. This method allows developers to normalize values before they are persisted in the database.

Understanding Load, Require, and Autoload

When working with Ruby on Rails, it’s crucial to understand how different mechanisms load and manage files within your application. Three essential concepts to grasp are load, require, and autoload. Each of these serves a unique purpose and has its own set of characteristics. In this blog post, we’ll delve into these concepts, highlighting their differences and providing examples of their usage.

How to Iterate Over an Array in Groups in Ruby and Rails

Ruby’s each_slice and in_groups_of methods are used to iterate over an array in groups of a certain size. The each_slice method takes a single argument, which is the size of the group. The in_groups_of method takes two arguments, the first is the size of the group and the second is the value that should be used to fill the groups that do not have the exact size.

Why Software Development Companies Make Ideal Startup Studios

Maybe you’ve noticed that more and more software development companies are turning into startup studios. It’s not just a trend; it’s a smart business move. Here’s why it’s happening, in plain and simple terms:

Exploring Ruby Documentation with ri

In Ruby, the command ri is used to access the built-in documentation (also known as “RDoc”) of a library, class, method, or specific topic. ri is an abbreviation for “Ruby Interactive” or “Ruby Index.”

Exploring 'Frozen String Literal': A Ruby Magic Comment

A comment in Ruby on Rails (and in programming in general) is a piece of text that is ignored by the interpreter when executing the code. Comments are used to provide explanations, documentation, or notes within the code to make it more understandable.

Introducing the ActiveRecord::Base::normalizes API Method in Rails 7.1

Rails 7.1 introduced a new method called ActiveRecord::Base::normalizes which can be used to declare normalizations for attribute values. This can be especially useful for sanitizing user input, ensuring consistent formatting, or cleaning up data from external sources.

Exploring OpenStruct and Struct

In Ruby, both OpenStruct and Struct provide ways to create objects with predefined attributes. However, they differ in functionality and flexibility. Let’s explore the differences between OpenStruct and Struct, and showcase examples to illustrate their usage.

Understanding the Differences: Traditional Forms vs. Form Objects in Rails

In Ruby on Rails, handling complex forms efficiently and maintaining clean and organized code is crucial. This is where Form Objects come into play. Let’s explore the concept of Form Objects and highlight the key differences between using a Form Object and a traditional form approach. Let’s dive in!