feat: add user index page and update navigation
- Implement users index action in UsersController - Create view for displaying all users with gravatar - Update header to link to users index - Add styles for user list display This commit introduces a new feature that allows logged-in users to view a list of all registered users. It includes necessary controller actions, view templates, and styling to improve the user interface.
This commit is contained in:
parent
97c91fc8f3
commit
cf76756f55
@ -2,6 +2,7 @@
|
||||
|
||||
/* color */
|
||||
$light-gray: #777;
|
||||
$gray-lighter: #D3D3D3;
|
||||
|
||||
/* universal */
|
||||
body {
|
||||
@ -187,3 +188,14 @@ input {
|
||||
width: auto;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
/* Users index */
|
||||
.users {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
li {
|
||||
overflow: auto;
|
||||
padding: 10px 0;
|
||||
border-bottom: 1px solid $gray-lighter;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,12 @@
|
||||
class UsersController < ApplicationController
|
||||
include SessionsHelper
|
||||
before_action :logged_in_user, only: [ :edit, :update ]
|
||||
before_action :logged_in_user, only: [ :index, :edit, :update ]
|
||||
before_action :correct_user, only: [ :edit, :update ]
|
||||
|
||||
def index
|
||||
@users = User.all
|
||||
end
|
||||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
# debugger
|
||||
|
@ -1,5 +1,6 @@
|
||||
module UsersHelper
|
||||
def gravatar_for(user, size: 80)
|
||||
def gravatar_for(user, options = { size: 80 })
|
||||
size = options[:size]
|
||||
gravatar_id = Digest::MD5.hexdigest(user.email.downcase)
|
||||
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
|
||||
image_tag(gravatar_url, alt: user.name, class: "gravatar")
|
||||
|
@ -18,7 +18,7 @@
|
||||
<li><%= link_to "Home", root_url %></li>
|
||||
<li><%= link_to "Help", help_url %></li>
|
||||
<% if logged_in? %>
|
||||
<li><%= link_to "Users", '#' %></li>
|
||||
<li><%= link_to "Users", users_path %></li>
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
Account <b class="caret"></b>
|
||||
|
12
app/views/users/index.html.erb
Normal file
12
app/views/users/index.html.erb
Normal file
@ -0,0 +1,12 @@
|
||||
<% provide(:title, 'All users') %>
|
||||
|
||||
<h1>All users</h1>
|
||||
|
||||
<ul class="users">
|
||||
<% @users.each do |user| %>
|
||||
<li>
|
||||
<%= gravatar_for user, size: 50 %>
|
||||
<%= link_to user.name, user %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
@ -10,6 +10,11 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should redirect index when not logged in" do
|
||||
get users_path
|
||||
assert_redirected_to login_url
|
||||
end
|
||||
|
||||
test "Should get sign up title" do
|
||||
get signup_path
|
||||
assert_response :success
|
||||
|
Loading…
Reference in New Issue
Block a user