$ rails new turboframes -d postgresql
$ cd turboframes
$ bin/setup$ rails generate scaffold book title author
$ rails db:migrate
$ rails generate scaffold album title artist
$ rails db:migrate$ rails generate controller home index
$ rails generate controller LatestAlbums index
$ rails generate controller LatestBooks indexconfig/routes.rb
root "home#index"
resources :albums
resources :books
resources :latest_albums
resources :latest_booksUpdate app/controllers/latest_books_controller.rb
class LatestBooksController < ApplicationController
layout false
def index
@books = Book.order(created_at: :desc).limit(5)
end
endUpdate app/controllers/latest_albums_controller.rb
class LatestAlbumsController < ApplicationController
layout false
def index
@albums = Album.order(created_at: :desc).limit(5)
end
endCreate app/views/home/index.html.erb
<h1>Home</h1>
<%= turbo_frame_tag :latest_books, src: latest_books_path, target: :_top, loading: :lazy do %>
<p>Loading...</p>
<% end %>
<%= turbo_frame_tag :latest_albums, src: latest_albums_path, target: :_top, loading: :lazy do %>
<p>Loading...</p>
<% end %>- first argument is the ID of the frame
srcspecifies the path to load the contents fromtargetspecifies that all links within the turbo frame should open up outside the turbo frameloadingwith :lazyas an argument specifies to not load the turbo frame until it is in the viewport, potentially preventing unnecessary loading
Update app/views/latest_books/index.html.erb
<%= turbo_frame_tag :latest_books do %>
<h2>Latest Books</h2>
<ul>
<% @books.each do |book| %>
<li><%= link_to book.title, book %></li>
<% end %>
</ul>
<% end %>Update app/views/latest_albums/index.html.erb
<%= turbo_frame_tag :latest_albums do %>
<h2>Latest Albums</h2>
<ul>
<% @albums.each do |album| %>
<li><%= link_to album.title, album %></li>
<% end %>
</ul>
<% end %>https://github.com/rails/importmap-rails#expected-errors-from-using-the-es-module-shim