Weekly Digest #3 : Rails 8 introduces a built-in rate limiting API
Curated and handpicked Ruby on Rails blogs.
Introduction
In this issue, we have picked 10 interesting articles published last week that are worth reading. These articles cover topics such as rails8 rate limit, ruby 3.3, full-text search, duck typing, custom URL helpers, turbo views, ActiveRecord association, and ahoy analytics. Consider subscribing, liking, and sharing it.
1. Rails 8 introduces a built-in rate-limiting API
Rails 8.0 introduces a native rate-limiting feature to the Action Controller, streamlining the process and eliminating the need for external gems. The rate_limit method allows developers to define limits within their controller actions, specifying the maximum allowed requests and the corresponding timeframe.
2. What is new in Ruby 3.3
Ruby 3.3 has introduced several new features, enhancements, and bugfixes to the Ruby community. Prism Parser is now the default gem, offering improved reliability and performance. YJIT, a Just-In-Time compiler developed by Shopify, has been improved with Ruby 3.3, allowing for faster application startup and less memory usage. YJIT now supports splat and optional parameters in methods, making core tasks like comparisons and type-checks faster.
Code-Along & build an advanced e-learning platform. Biggest, Most complete Ruby on Rails 6 course ( Affiliated )
Ruby on Rails: Learn 25+ gems and build a Startup MVP
4.5 ⭐ | 5k students
3. Duck Typing in Ruby
Duck typing is a programming concept where an object's suitability in a given context is determined by the presence of certain methods and properties, rather than the type of object itself. This concept enhances Object-Oriented Programming (OOP) in Ruby, which stands out for its elegant syntax and dynamic nature. Duck typing allows objects to be more fluid in their roles within a program, enabling developers to write more generic and reusable code.
4. Custom URL Helpers in Rails with the direct Method
In this post, the author explores the direct method in the Rails Router, which allows users to define custom URL helpers for their application. Campfire, the first ONCE product from 37signals, is a valuable resource for learning and extracting useful patterns, ideas, and best practices. The router is the entry point of a Rails application, acting as the gatekeeper for all incoming HTTP requests. The router is responsible for inspecting and sending them to a controller action, even filtering and rejecting them if necessary.
5. Full-Text Search for Ruby on Rails with Litesearch
This post discusses the use of Litesearch in Ruby on Rails, a convenience wrapper built around FTS5, SQLite's virtual table-based full-text search module. It focuses on the ActiveRecord integration and demonstrates how to configure a prompts index page with a search bar to query a database for specific prompts. Litesearch is a Ruby module that provides a simple API to perform text searches against a SQLite database.
Learn to make innovative web apps with Ruby on Rails and unleash your creativity ( Affiliated )
The Complete Ruby on Rails Developer Course
Bestseller | 4.4 ⭐ | 100k+ students
6. Visualizing Ahoy analytics in Rails
Honeybadger co-founder Joshua Wood demonstrates how to graph Ahoy page views in Rails with Chartkick, and previews their upcoming observability tool, Insights. Ahoy is used for first-party analytics in Rails, allowing developers to visualize data in their application alongside other data and code. Chartkick and Groupdate are used to create charts of all page views, allowing for better tracking of analytics and dashboards.
7. Are You Using includes
, joins
, and preload
Correctly in Ruby on Rails?
In Ruby on Rails, managing database queries is crucial for building scalable and high-performance applications. One common issue is the N+1 query problem, which can slow down the app. Rails provides methods to combat this, including includes, joins, and preload. Understanding when and how to use these methods can significantly optimize your app's database interactions.
8. Anonymous Block Forwarding in Ruby
In this article, the author discusses the anonymous block forwarding feature in Ruby 3.1, which allows users to replace execute(&block) calls with execute(&). This feature saves users from creating a variable (most likely blk) and looks nice. The anonymous block forwarding syntax, which was added in Ruby 2.7, allows for forwarding all arguments passed to a method, including positional, named, and block arguments, using the three-dot syntax.
Advance your SQL skills by practicing it (Affiliated)
Checkout analystbuilder platform for more
Use discount code: ABNEW20OFF for 20% off
9. Upcasting events in RailsEventStore
The article discusses domain-driven design in Ruby on Rails, specifically focusing on upcasting events in RailsEventStore. The authors faced a dilemma when implementing a new business feature in an aggregate model, which they felt was too feature-driven. They decided to implement the feature in the application layer, but it felt hacky. After writing test cases, they realized that the aggregate class had two methods that did the same thing but produced different events.
10. Turbo View Transitions in Rails
Avi Flombaum discusses the use of View Transitions in Rails, a CSS method that animates transitions between states of the view, such as full page reload or DOM update. The Turbo library, released with Turbo 2.0, supports view transitions, combining with Rails for impressive reactivity. The application uses Photos with URLs and likes count, and a PhotosController with index, show, and update actions. The application uses a classic view transition between the index and show views, which is already a fade transition.
That’s a wrap for this week. If you have any feedback, requests, or improvements for this newsletter consider commenting so that we can work on improvements for the next one.