Total Blog Views: 96
Blog Status: publish
Created By: swaz_ahmed Created at: 02-12-2025
Tags: ror rails8 kamal solid solid cable solid cache solid queue propshaft kamal2 features
Ruby on Rails has always been a beloved framework for building web applications, thanks to its simplicity, flexibility, and developer-friendly features. With Rails 8, the framework has received several exciting new additions that help improve the performance, developer experience, and functionality of applications. Whether you're building a new app or upgrading an existing one, Rails 8 offers powerful tools to make your job easier.
In this blog, we’ll explore the most exciting new features in Rails 8, providing practical examples and insights into how they can improve your development workflow.
Turbo Frames and Streams are part of the Hotwire framework introduced in Rails to reduce reliance on JavaScript for dynamic updates. Turbo 8, in particular, brings several improvements to speed up page interactions without needing full-page reloads.
Here’s how you can use Turbo Frames to update parts of a page without reloading the entire page:
<!-- app/views/posts/index.html.erb --> <h1>Posts</h1> <%= turbo_frame_tag "posts" do %> <%= render @posts %> <% end %> <!-- app/views/posts/_post.html.erb --> <div id="post_<%= post.id %>"> <h2><%= post.title %></h2> <%= link_to 'Show', post_path(post), data: { turbo_frame: "post_#{post.id}" } %> </div> <!-- app/views/posts/show.html.erb --> <%= turbo_frame_tag "post_#{@post.id}" do %> <h1><%= @post.title %></h1> <%= @post.content %> <% end %>
How it works:
When you click on the "Show" link, only the content within the post_<%= post.id %>
frame will be replaced. This allows for faster updates and a smoother user experience.
STRICT
ModeRails 8 introduces STRICT Mode to ActiveRecord, which ensures that database queries are more reliable and consistent. This new feature can be incredibly helpful in catching database issues early.
In STRICT Mode, if you attempt to insert a NULL
value into a column that should not accept NULL
values, Rails will throw an exception.
# app/models/user.rb
class User < ApplicationRecord
validates :name, presence: true
validates :email, presence: true
end
# This will raise an error because 'name' and 'email' are required
User.create(name: nil, email: '[email protected]')
How it works:
By enforcing stricter checks on model attributes, Rails ensures that no invalid data makes it into your database.
Caching in Rails has always been a powerful tool to enhance performance, and in Rails 8, it’s been made even better. Rails 8 introduces cache versioning, eager cache loading, and more caching layers.
You can easily version cache keys and manage cache expiration using Rails 8.
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts = Rails.cache.fetch('posts', version: 'v1') do
Post.all.to_a
end
end
end
How it works:
version: 'v1'
parameter. This means that when you update your posts (or change any cached data), you can force the cache to expire by changing the version number.
Rails 8 introduces asynchronous queries to Active Record, enabling non-blocking database operations that improve the performance of your application.
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
# Perform an async database query
@posts = Post.where(published: true).async_find_each do |post|
# Process each post asynchronously
Rails.logger.info("Processing post #{post.id}")
end
end
end
How it works:
async_find_each
allows you to process records without blocking the main thread, which is useful when dealing with large datasets or long-running queries.
Rails 8 has deepened the integration of Webpacker, which is used to manage JavaScript, CSS, and other front-end assets. Webpacker now fully supports Webpack 5, allowing you to take advantage of the latest JavaScript tooling.
// app/javascript/packs/application.js
import { helloWorld } from './modules/hello_world'
helloWorld()
// app/javascript/modules/hello_world.js
export function helloWorld() {
console.log('Hello from Webpacker and Webpack 5!')
}
How it works:
Rails 8 introduces better debugging tools, including an integrated performance profiler and improved rails console
.
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index # Start profiling Rails.performance do
@posts = Post.all
end
end
end
How it works:
Rails 8 fully supports Ruby 3.x and introduces features such as keyword arguments, pattern matching, and garbage collection optimizations that Ruby 3 brings.
# app/models/user.rb
class User < ApplicationRecord
def self.find_by_status(status)
case status
in :active
active
in :inactive
inactive
else
none
end
end
end
How it works:
Rails 8 brings enhanced security features, including stronger CSRF protections and better password hashing mechanisms.
# config/initializers/csrf_protection.rb
Rails.application.config.action_controller.default_protect_from_forgery = true
How it works:
With Rails 8, the framework continues to evolve, making web development faster, more efficient, and more secure. Features like Turbo 8, async querying, and improved caching mechanisms will help developers build even more responsive and optimized applications. With the continued improvements to ActiveRecord, Webpacker, and developer tools, Rails 8 solidifies its place as one of the best frameworks for building modern web applications.
Whether you're a Rails veteran or just getting started, Rails 8 brings new tools and features that will make your development process smoother and your applications more powerful.
Happy coding!
we have the “Get things executed” lifestyle at our place of work. There are not any excuses, no if’s or however’s in our dictionary. committed to navigating the ship of creativity to create cell answers, we resolve the real-lifestyles troubles of our clients and their clients. Our passion for work has won us many awards, year after 12 months.
© Copyright Shadbox. All Rights Reserved
Rate Blog :
Share on :
Do you have any blog suggestion? please click on the link