Skip to content

Commit

Permalink
top bar
Browse files Browse the repository at this point in the history
  • Loading branch information
a-lavis committed Apr 3, 2023
1 parent 09676e4 commit 5f29cf7
Show file tree
Hide file tree
Showing 9 changed files with 51 additions and 4 deletions.
5 changes: 5 additions & 0 deletions 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
8 changes: 8 additions & 0 deletions app/controllers/top_bar_controller.rb
@@ -0,0 +1,8 @@
class TopBarController < TurboOnlyController
def index
end

def turbo_only_layout
"top_bar"
end
end
9 changes: 9 additions & 0 deletions 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
3 changes: 3 additions & 0 deletions app/views/layouts/_main.html.erb
@@ -0,0 +1,3 @@
<%= turbo_frame_tag :main do %>
<%= yield %>
<% end %>
6 changes: 2 additions & 4 deletions app/views/layouts/application.html.erb
Expand Up @@ -11,11 +11,9 @@
</head>

<body>
<%= turbo_frame_tag :side_bar do %>
<p> TODO: Create a reactive sidebar using Turbo! </p>
<% end %>
<%= turbo_frame_tag :top_bar, src: top_bar_index_path %>
<%= turbo_frame_tag :main_content do %>
<%= render 'layouts/main' do %>
<%= yield %>
<% end %>
</body>
Expand Down
10 changes: 10 additions & 0 deletions app/views/layouts/top_bar.html.erb
@@ -0,0 +1,10 @@
<html>
<head>
<%= yield :head %>
</head>
<body>
<%= turbo_frame_tag :top_bar do %>
<%= yield %>
<% end %>
</body>
</html>
10 changes: 10 additions & 0 deletions app/views/layouts/turbo_rails/frame.html.erb
@@ -0,0 +1,10 @@
<html>
<head>
<%= yield :head %>
</head>
<body>
<%= render 'layouts/main' do %>
<%= yield %>
<% end %>
</body>
</html>
3 changes: 3 additions & 0 deletions app/views/top_bar/index.html.erb
@@ -0,0 +1,3 @@
<h1>TopBar#index</h1>
<p>Find me in app/views/top_bar/index.html.erb</p>
<%= link_to "Link to this page", top_bar_index_path %>
1 change: 1 addition & 0 deletions 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

Expand Down

0 comments on commit 5f29cf7

Please sign in to comment.