Techdots
Blog
What’s New in Ruby on Rails 8
Discover the power of Ruby on Rails 8! This latest release enhances development with built-in authentication, a new asset pipeline, and streamlined deployment tools. Explore its exciting features!

Ruby on Rails has been the backbone of countless web applications for nearly two decades. With each new version, it keeps getting faster, smarter, and more user-friendly. And now, Rails 8 is here, bringing a fresh wave of powerful features, smarter tools, and exciting updates.

No matter if you're a seasoned Rails developer or just curious about what’s new, this latest release has something to make your work easier, your apps better, and your coding journey more enjoyable. 

Let’s get to know Rails 8 and explore how it’s shaping the future of web development.

Ruby on Rails 8: An Overview

Ruby on Rails 8 is here, and it’s packed with groundbreaking features designed to make building, deploying, and scaling applications even simpler. From built-in authentication to turbocharged background processing, Rails 8 is a testament to its philosophy as the One Person Framework.

An exciting array of features, bug fixes, and enhancements are being brought about by the latest version of Ruby on Rails. In addition to adding new features and optimization to make Rails development even more efficient and pleasurable, this release expands upon the framework of Rails 7.2. 

Important features include the addition of Propshaft as the new default asset pipeline, major ActiveRecord upgrades, and an interface with Kamal 2 for hassle-free deployments. Additionally, Rails 8 offers a number of SQLite integration enhancements that make it a practical choice for production use.

Authentication in Rails 8

Introduction to Rails 8 Authentication: Rails 8 simplifies user authentication by providing a built-in solution right out of the box. Whether you're building a small app or a large-scale application, Rails 8 makes it seamless to secure user access.

Key Features

Here are the key features of Ruby on Rails 8:

Multi-Factor Authentication (MFA) add an extra layer of security with native MFA support.

Example implementation:

Rails.application.config.authentication.mfa = true

Ruby on Rails 8 improve password hashing. It utilizes modern hashing algorithms like Argon2 for secure password storage.

Another key feature of Ruby on Rails 8 is encryption enhancements. It provides out-of-the-box encryption for sensitive data using Rails 8's updated cryptographic standards.

Best Practices:

  1. Use MFA for all admin users.
  2. Regularly rotate encryption keys using Rails' ActiveSupport::MessageEncryptor.

Here are the new features in Ruby on rails 8:

Propshaft: The New Asset Pipeline

Propshaft replaces Sprockets as the default asset pipeline in Rails 8, offering simplicity, speed, and better integration with modern front-end tooling. Propshaft is build on an era where bundling asset to save on HTTP connections is no longer urgent. 

Key Improvements:

  • Faster Compilation: Optimized for handling modern JavaScript and CSS libraries.
  • Smaller Bundle Sizes: Reduces asset bloat by intelligently resolving dependencies.

How to Transition to Propshaft:

  1. Update Gemfile:

gem 'propshaft', '~> 1.0'

  1. Migrate your assets/ directory to match Propshaft's directory structure.

Real-World Example: Propshaft improved asset loading times by 40% in a recent project by streamlining how files were served in production.

Solid Trifacta: Type Safety in Rails 8

Solid Trifacta is a new library that improves type safety in Ruby. It allows developers to declare types explicitly, catching errors earlier in the development cycle. But, why it matters when we already have safety measures in Rails 8. Well, here are the reasons why Solid Trifacta matters:

  • Prevents Type Bugs: Catches mismatched data types at runtime.
  • Improves Maintainability: Makes complex codebases easier to understand.

Integration Guide

To integrate the Solid Trifacta, follow this integration guide:

class User

 include Solid::Trifacta

 attribute :email, String

end

Pro Tip: Use Solid Trifacta in conjunction with Sorbet or RBS for even greater type safety.

Thruster: Turbocharged Background Processing

Thruster is the latest addition to Rails 8, designed to handle background jobs more efficiently than ever. It provides a lightweight yet powerful alternative to ActiveJob. With Thruster, there is zero configuration and your web pages run as fast as they can, reducing the time of loading pages. 

Here are the key advantages of Thruster:

  • Parallel Processing: Handles high-throughput jobs with ease.
  • Low Latency: Designed for real-time applications.

Sample Implementation:

class EmailJob < Thruster::Job

 queue_as :emails

 def perform(user_id)

   UserMailer.welcome_email(user_id).deliver_now

 end

end

Best Practices

To effectively use the Thruster, make sure to follow these practices:

  • Use Thruster for computationally intensive tasks like video encoding.
  • Combine Thruster with caching (e.g., Solid Cache) to minimize redundant processing.

Kamal 2: Next-Level Deployment Tooling

What’s New in Kamal 2? Kamal 2 is the next iteration of Rails’ deployment tool, making zero-downtime deployments and rollbacks simpler and faster. No matter where you’re deploying your application. Kamal takes a fresh Linux box and turns it into an application or necessary server with just a single “Kamal setup” command. 

New Features:

  • Built-In Cloud Integrations: Support for AWS, DigitalOcean, and other popular providers.
  • Simplified Configurations: Declarative syntax for deployment pipelines.

Step-by-Step Deployment Guide

Follow this step-by-step guide to deploy Kamal 2 on ruby on rails 8:

To start with, install Kamal 2 in your sysytem.

gem install kamal

After installation, the next step is to configure kamal.yml:

deploy:

 app: my_app

servers:

 - 192.168.1.1

The last step is to deploy kamal for proper setup.

kamal deploy

Key Changes in Ruby on rails 8

Here are the key changes introduced in Ruby on Rails 8:

  • In PostgreSQL, Rails 8 now makes a distinction between float4 and float8.
    Multiple tables can now be dropped simultaneously with drop_table.
  • Native partitioning and PostgreSQL table inheritance are now supported. 
  • Fixtures can now be inserted in bulk to enhance data seeding efficiency. 
  • The database schema must now be loaded before beginning any migrations to a new database. 
  • The actions create_schema and drop_schema can now be reversed. Because to improvements such as datetime with accuracy, Rails 8 now requires MySQL 5.6.4 or above.
  • In order to track SQL statements back to the application code and determine which database is being used, development environments by default allow query log tags.

Conclusion

Rails 8 is a game-changer for developers. From its enhanced authentication capabilities to its modern asset pipeline and deployment tools, it continues to uphold its promise of simplicity and power. Whether you're a solo developer or part of a team, Rails 8 equips you to build scalable and secure applications effortlessly.

Contact
Us
Our Technology Stack

Work with future-proof technologies

Typescript
React JS
Node JS
Angular
Vue JS
Rails
Ruby on Rails
Go
Next JS
AWS
SASS