diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09705d1..a2cda80 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,2 +1,7 @@ class ApplicationController < ActionController::Base + def only_turbo + return if turbo_frame_request? + render plain: "This controller only responds to Turbo Frame requests", + status: :not_acceptable + end end diff --git a/app/controllers/top_bar_controller.rb b/app/controllers/top_bar_controller.rb new file mode 100644 index 0000000..46f8604 --- /dev/null +++ b/app/controllers/top_bar_controller.rb @@ -0,0 +1,8 @@ +class TopBarController < TurboOnlyController + def index + end + + def turbo_only_layout + "top_bar" + end +end diff --git a/app/controllers/turbo_only_controller.rb b/app/controllers/turbo_only_controller.rb new file mode 100644 index 0000000..0065330 --- /dev/null +++ b/app/controllers/turbo_only_controller.rb @@ -0,0 +1,9 @@ +class TurboOnlyController < ApplicationController + prepend_before_action :only_turbo + + def turbo_only_layout + raise NotImplementedError, "#{self.class} must implement turbo_only_layout" + end + + layout :turbo_only_layout +end diff --git a/app/views/layouts/_main.html.erb b/app/views/layouts/_main.html.erb new file mode 100644 index 0000000..f2ddab1 --- /dev/null +++ b/app/views/layouts/_main.html.erb @@ -0,0 +1,3 @@ +<%= turbo_frame_tag :main do %> + <%= yield %> +<% end %> diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 24e834e..4fe4f8d 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -11,11 +11,9 @@ - <%= turbo_frame_tag :side_bar do %> -

TODO: Create a reactive sidebar using Turbo!

- <% end %> + <%= turbo_frame_tag :top_bar, src: top_bar_index_path %> - <%= turbo_frame_tag :main_content do %> + <%= render 'layouts/main' do %> <%= yield %> <% end %> diff --git a/app/views/layouts/top_bar.html.erb b/app/views/layouts/top_bar.html.erb new file mode 100644 index 0000000..196d48f --- /dev/null +++ b/app/views/layouts/top_bar.html.erb @@ -0,0 +1,10 @@ + + + <%= yield :head %> + + + <%= turbo_frame_tag :top_bar do %> + <%= yield %> + <% end %> + + diff --git a/app/views/layouts/turbo_rails/frame.html.erb b/app/views/layouts/turbo_rails/frame.html.erb new file mode 100644 index 0000000..88a42db --- /dev/null +++ b/app/views/layouts/turbo_rails/frame.html.erb @@ -0,0 +1,10 @@ + + + <%= yield :head %> + + + <%= render 'layouts/main' do %> + <%= yield %> + <% end %> + + diff --git a/app/views/top_bar/index.html.erb b/app/views/top_bar/index.html.erb new file mode 100644 index 0000000..8f9e912 --- /dev/null +++ b/app/views/top_bar/index.html.erb @@ -0,0 +1,3 @@ +

TopBar#index

+

Find me in app/views/top_bar/index.html.erb

+<%= link_to "Link to this page", top_bar_index_path %> diff --git a/config/routes.rb b/config/routes.rb index f7353ce..9bf2496 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + resources :top_bar, only: [:index] resources :home, only: [:index] # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html