Skip to content

Commit

Permalink
Use cool path helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
drjole committed Oct 25, 2024
1 parent 90f06b5 commit ede8598
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
14 changes: 7 additions & 7 deletions app/views/application/_navigation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,40 @@
<div class="font-bold flex flex-1 justify-evenly">

<% if policy(User).index? %>
<%= link_to users_path do %>
<%= link_to User do %>
<i class="bi bi-people"></i>
<% end %>
<% end %>

<% if policy(User).create? %>
<%= link_to new_user_path do %>
<%= link_to %i[new user] do %>
<i class="bi bi-person-plus"></i>
<% end %>
<% end %>

<% if policy(:leaderboards).show? %>
<%= link_to leaderboard_path do %>
<%= link_to :leaderboard do %>
<i class="bi bi-trophy"></i>
<% end %>
<% end %>

<% if policy(Game).index? %>
<%= link_to games_path do %>
<%= link_to Game do %>
<i class="bi bi-list-ul"></i>
<% end %>
<% end %>

<% if policy(Game).create? %>
<%= link_to new_game_path do %>
<%= link_to %i[new game] do %>
<i class="bi bi-plus-circle"></i>
<% end %>
<% end %>

<%= link_to profile_path do %>
<%= link_to :profile do %>
<i class="bi bi-person-circle text-green-500 hover:text-green-700"></i>
<% end %>

<%= button_to logout_path, method: :delete, class: "hover:text-slate-400", form: { class: "inline" } do %>
<%= button_to :logout, method: :delete, class: "hover:text-slate-400", form: { class: "inline" } do %>
<i class="bi bi-door-open"></i>
<% end %>

Expand Down
4 changes: 2 additions & 2 deletions app/views/games/_game.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<div class="flex flex-col gap-4">
<div>
<% if policy(player.user).show? %>
<%= link_to "Show profile", user_path(player.user) %>
<%= link_to "Show profile", player.user %>
<% end %>
</div>
</div>
Expand All @@ -54,7 +54,7 @@
</ul>

<% if policy(game).update? %>
<%= link_to "Edit this game", edit_game_path(game) %>
<%= link_to "Edit this game", [:edit, game] %>
<% end %>
</details>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/games/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% if @games.none? %>
There are not games yet.
<% if policy(Game).create? %>
<%= link_to "Create a new one.", new_game_path %>
<%= link_to "Create a new one.", %i[new game] %>
<% end %>
<% end %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
<% end %>
</div>

<%= link_to "Forgot password?", new_password_reset_path %>
<%= link_to "Forgot password?", %i[new password_reset] %>
2 changes: 1 addition & 1 deletion app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<p>
<% if policy(@user).update? %>
<%= link_to @user == Current.user ? %i[profile edit] : [:edit, @user] do %>
<%= link_to @user == Current.user ? %i[edit profile] : [:edit, @user] do %>
<i class="bi bi-pencil"></i>
<% end %>
<% end %>
Expand Down
4 changes: 1 addition & 3 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@
resource :profile_picture, only: [:edit, :update, :destroy]
resource :password, only: [:edit, :update]
end
resource :profile, only: [:show, :edit], controller: :users
resource :leaderboard, only: [:show]

get "/login", to: "sessions#new"
delete "/logout", to: "sessions#destroy"
get "/register", to: "users#new"

get "/profile", to: "users#show"
get "/profile/edit", to: "users#edit"

# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", :as => :rails_health_check
Expand Down

0 comments on commit ede8598

Please sign in to comment.