Skip to content

Commit 11f928b

Browse files
committed
user sign in page and navbar
1 parent 42d44c4 commit 11f928b

File tree

15 files changed

+95
-8
lines changed

15 files changed

+95
-8
lines changed

app/assets/stylesheets/application.sass.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@import "components/visually_hidden";
1414
@import "components/quote";
1515
@import "components/turbo_progress_bar";
16+
@import "components/navbar";
1617

1718
// Layouts
1819
@import "layouts/container";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
.navbar {
2+
display: flex;
3+
align-items: center;
4+
box-shadow: var(--shadow-large);
5+
padding: var(--space-xs) var(--space-m);
6+
margin-bottom: var(--space-xxl);
7+
background-color: (var(--color-white));
8+
9+
&__brand {
10+
font-weight: bold;
11+
font-size: var(--font-size-xl);
12+
color: var(--color-text-header);
13+
}
14+
15+
&__name {
16+
font-weight: bold;
17+
margin-left: auto;
18+
margin-right: var(--space-s);
19+
color: var(--color-text-header);
20+
}
21+
22+
&__right {
23+
margin-left: auto;
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
class ApplicationController < ActionController::Base
2+
before_action :authenticate_user!, unless: :devise_controller?
3+
4+
private
5+
6+
def current_company
7+
@current_company ||= current_user.company if user_signed_in?
8+
end
9+
helper_method :current_company
210
end

app/controllers/pages_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class PagesController < ApplicationController
2+
skip_before_action :authenticate_user!
3+
4+
def home
5+
end
6+
end

app/controllers/quotes_controller.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ class QuotesController < ApplicationController
22
before_action :set_quote, only: [:show, :edit, :update, :destroy]
33

44
def index
5-
@quotes = Quote.desc_id_ordered
5+
# @quotes = Quote.desc_id_ordered
6+
@quotes = current_company.quotes.desc_id_ordered
67
end
78

89
def show
@@ -13,7 +14,8 @@ def new
1314
end
1415

1516
def create
16-
@quote = Quote.new(quote_params)
17+
# @quote = Quote.new(quote_params)
18+
@quote = current_company.quotes.build(quote_params)
1719

1820
if @quote.save
1921
respond_to do |format|
@@ -47,7 +49,8 @@ def destroy
4749
private
4850

4951
def set_quote
50-
@quote = Quote.find(params[:id])
52+
# @quote = Quote.find(params[:id])
53+
@quote = current_company.quotes.find(params[:id])
5154
end
5255

5356
def quote_params

app/models/user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ class User < ApplicationRecord
22
devise :database_authenticatable, :validatable
33

44
belongs_to :company
5+
6+
def name
7+
email.split("@").first.capitalize
8+
end
59
end

app/views/layouts/_navbar.html.erb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<header class="navbar">
2+
<% if user_signed_in? %>
3+
<div class="navbar__brand">
4+
<%= current_company.name %>
5+
</div>
6+
<div class="navbar__name">
7+
<%= current_user.name %>
8+
</div>
9+
<%= button_to "Sign out",
10+
destroy_user_session_path,
11+
method: :delete,
12+
class: "btn btn--dark" %>
13+
<% else %>
14+
<%= link_to "Sign in",
15+
new_user_session_path,
16+
class: "btn btn--dark navbar__right" %>
17+
<% end %>
18+
</header>

app/views/layouts/application.html.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
</head>
1212

1313
<body>
14+
<%= render "layouts/navbar" %>
1415
<%= yield %>
16+
<% console if Rails.env == 'development' %>
1517
</body>
1618
</html>

app/views/pages/home.html.erb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<main class="container">
2+
<h1>Quote editor</h1>
3+
<p>A blazing fast quote editor built with Hotwire</p>
4+
5+
<% if user_signed_in? %>
6+
<%= link_to "View quotes", quotes_path, class: "btn btn--dark" %>
7+
<% else %>
8+
<%= link_to "Sign in", new_user_session_path, class: "btn btn--dark" %>
9+
<% end %>
10+
</main>

config/routes.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
# Can be used by load balancers and uptime monitors to verify that the app is live.
77
get "up" => "rails/health#show", as: :rails_health_check
88

9-
# Defines the root path route ("/")
10-
root "quotes#index"
9+
root to: "pages#home"
1110

1211
resources :quotes
1312
end

0 commit comments

Comments
 (0)