Ressource User
This commit is contained in:
parent
c15fbf8e41
commit
94590699b9
|
@ -0,0 +1,70 @@
|
||||||
|
class UsersController < ApplicationController
|
||||||
|
before_action :set_user, only: %i[ show edit update destroy ]
|
||||||
|
|
||||||
|
# GET /users or /users.json
|
||||||
|
def index
|
||||||
|
@users = User.all
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /users/1 or /users/1.json
|
||||||
|
def show
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /users/new
|
||||||
|
def new
|
||||||
|
@user = User.new
|
||||||
|
end
|
||||||
|
|
||||||
|
# GET /users/1/edit
|
||||||
|
def edit
|
||||||
|
end
|
||||||
|
|
||||||
|
# POST /users or /users.json
|
||||||
|
def create
|
||||||
|
@user = User.new(user_params)
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
if @user.save
|
||||||
|
format.html { redirect_to user_url(@user), notice: "User was successfully created." }
|
||||||
|
format.json { render :show, status: :created, location: @user }
|
||||||
|
else
|
||||||
|
format.html { render :new, status: :unprocessable_entity }
|
||||||
|
format.json { render json: @user.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# PATCH/PUT /users/1 or /users/1.json
|
||||||
|
def update
|
||||||
|
respond_to do |format|
|
||||||
|
if @user.update(user_params)
|
||||||
|
format.html { redirect_to user_url(@user), notice: "User was successfully updated." }
|
||||||
|
format.json { render :show, status: :ok, location: @user }
|
||||||
|
else
|
||||||
|
format.html { render :edit, status: :unprocessable_entity }
|
||||||
|
format.json { render json: @user.errors, status: :unprocessable_entity }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# DELETE /users/1 or /users/1.json
|
||||||
|
def destroy
|
||||||
|
@user.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to users_url, notice: "User was successfully destroyed." }
|
||||||
|
format.json { head :no_content }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
|
def set_user
|
||||||
|
@user = User.find(params[:id])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Only allow a list of trusted parameters through.
|
||||||
|
def user_params
|
||||||
|
params.fetch(:user, {})
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,7 +5,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if controller_name == "users" %>
|
<% if controller_name == "users" %>
|
||||||
<%#= link_to "Users", users_path, class: common_classes + " " + active_classes %>
|
<%= link_to "Users", users_path, class: common_classes + " " + active_classes %>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%#= link_to "Users", users_path, class: common_classes + " " + inactive_classes %>
|
<%= link_to "Users", users_path, class: common_classes + " " + inactive_classes %>
|
||||||
<% end %>
|
<% end %>
|
|
@ -1,5 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
<div class="w-full">
|
<div class="w-full">
|
||||||
|
|
||||||
<div class="flex justify-between items-center">
|
<div class="flex justify-between items-center">
|
||||||
|
@ -15,11 +13,14 @@
|
||||||
<table class="min-w-full divide-y divide-gray-200">
|
<table class="min-w-full divide-y divide-gray-200">
|
||||||
<thead class="bg-gray-50">
|
<thead class="bg-gray-50">
|
||||||
<tr>
|
<tr>
|
||||||
|
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
|
Gravatar
|
||||||
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
Email
|
Email
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
Display name
|
Name
|
||||||
</th>
|
</th>
|
||||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||||
Created at
|
Created at
|
||||||
|
@ -35,11 +36,14 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<% @users.each do |user| %>
|
<% @users.each do |user| %>
|
||||||
<tr class="<%= cycle("bg-white", "bg-gray-50") %>">
|
<tr class="<%= cycle("bg-white", "bg-gray-50") %>">
|
||||||
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
|
<%= user_gravatar current_user, class: "h-10 w-10 rounded-full", size: 80 %>
|
||||||
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
<%= user.email %>
|
<%= user.email %>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">
|
||||||
<%= user.display_name %>
|
<%= user.name %>
|
||||||
</td>
|
</td>
|
||||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||||
<%= user.created_at %>
|
<%= user.created_at %>
|
|
@ -19,4 +19,5 @@ Rails.application.routes.draw do
|
||||||
resources :passwords, only: [:create, :edit, :new, :update], param: :password_reset_token
|
resources :passwords, only: [:create, :edit, :new, :update], param: :password_reset_token
|
||||||
|
|
||||||
resources :checks
|
resources :checks
|
||||||
|
resources :users
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||||
|
setup do
|
||||||
|
@user = users(:one)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get index" do
|
||||||
|
get users_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get new" do
|
||||||
|
get new_user_url
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should create user" do
|
||||||
|
assert_difference("User.count") do
|
||||||
|
post users_url, params: { user: { } }
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to user_url(User.last)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should show user" do
|
||||||
|
get user_url(@user)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should get edit" do
|
||||||
|
get edit_user_url(@user)
|
||||||
|
assert_response :success
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should update user" do
|
||||||
|
patch user_url(@user), params: { user: { } }
|
||||||
|
assert_redirected_to user_url(@user)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "should destroy user" do
|
||||||
|
assert_difference("User.count", -1) do
|
||||||
|
delete user_url(@user)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_redirected_to users_url
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue