?
This commit is contained in:
parent
e253a71fc4
commit
2696e1f184
33 changed files with 443 additions and 0 deletions
2
app/controllers/discord_users_controller.rb
Normal file
2
app/controllers/discord_users_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class DiscordUsersController < ApplicationController
|
||||
end
|
2
app/controllers/sessions_controller.rb
Normal file
2
app/controllers/sessions_controller.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class SessionsController < ApplicationController
|
||||
end
|
70
app/controllers/users_controller.rb
Normal file
70
app/controllers/users_controller.rb
Normal file
|
@ -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.require(:user).permit(:provider, :uid, :border)
|
||||
end
|
||||
end
|
2
app/helpers/discord_users_helper.rb
Normal file
2
app/helpers/discord_users_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module DiscordUsersHelper
|
||||
end
|
2
app/helpers/sessions_helper.rb
Normal file
2
app/helpers/sessions_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module SessionsHelper
|
||||
end
|
2
app/helpers/users_helper.rb
Normal file
2
app/helpers/users_helper.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
module UsersHelper
|
||||
end
|
4
app/models/discord.rb
Normal file
4
app/models/discord.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class DiscordUser < ApplicationRecord
|
||||
attr_accessible :discord_id, :username, :discriminator, :avatar
|
||||
validates :discord_id, :uniqueness => true
|
||||
end
|
2
app/models/user.rb
Normal file
2
app/models/user.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
class User < ApplicationRecord
|
||||
end
|
32
app/views/users/_form.html.erb
Normal file
32
app/views/users/_form.html.erb
Normal file
|
@ -0,0 +1,32 @@
|
|||
<%= form_with(model: user) do |form| %>
|
||||
<% if user.errors.any? %>
|
||||
<div style="color: red">
|
||||
<h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>
|
||||
|
||||
<ul>
|
||||
<% user.errors.each do |error| %>
|
||||
<li><%= error.full_message %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<div>
|
||||
<%= form.label :provider, style: "display: block" %>
|
||||
<%= form.text_field :provider %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.label :uid, style: "display: block" %>
|
||||
<%= form.text_field :uid %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.label :border, style: "display: block" %>
|
||||
<%= form.text_field :border %>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<%= form.submit %>
|
||||
</div>
|
||||
<% end %>
|
17
app/views/users/_user.html.erb
Normal file
17
app/views/users/_user.html.erb
Normal file
|
@ -0,0 +1,17 @@
|
|||
<div id="<%= dom_id user %>">
|
||||
<p>
|
||||
<strong>Provider:</strong>
|
||||
<%= user.provider %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Uid:</strong>
|
||||
<%= user.uid %>
|
||||
</p>
|
||||
|
||||
<p>
|
||||
<strong>Border:</strong>
|
||||
<%= user.border %>
|
||||
</p>
|
||||
|
||||
</div>
|
2
app/views/users/_user.json.jbuilder
Normal file
2
app/views/users/_user.json.jbuilder
Normal file
|
@ -0,0 +1,2 @@
|
|||
json.extract! user, :id, :provider, :uid, :border, :created_at, :updated_at
|
||||
json.url user_url(user, format: :json)
|
10
app/views/users/edit.html.erb
Normal file
10
app/views/users/edit.html.erb
Normal file
|
@ -0,0 +1,10 @@
|
|||
<h1>Editing user</h1>
|
||||
|
||||
<%= render "form", user: @user %>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<%= link_to "Show this user", @user %> |
|
||||
<%= link_to "Back to users", users_path %>
|
||||
</div>
|
14
app/views/users/index.html.erb
Normal file
14
app/views/users/index.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<p style="color: green"><%= notice %></p>
|
||||
|
||||
<h1>Users</h1>
|
||||
|
||||
<div id="users">
|
||||
<% @users.each do |user| %>
|
||||
<%= render user %>
|
||||
<p>
|
||||
<%= link_to "Show this user", user %>
|
||||
</p>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= link_to "New user", new_user_path %>
|
1
app/views/users/index.json.jbuilder
Normal file
1
app/views/users/index.json.jbuilder
Normal file
|
@ -0,0 +1 @@
|
|||
json.array! @users, partial: "users/user", as: :user
|
9
app/views/users/new.html.erb
Normal file
9
app/views/users/new.html.erb
Normal file
|
@ -0,0 +1,9 @@
|
|||
<h1>New user</h1>
|
||||
|
||||
<%= render "form", user: @user %>
|
||||
|
||||
<br>
|
||||
|
||||
<div>
|
||||
<%= link_to "Back to users", users_path %>
|
||||
</div>
|
10
app/views/users/show.html.erb
Normal file
10
app/views/users/show.html.erb
Normal file
|
@ -0,0 +1,10 @@
|
|||
<p style="color: green"><%= notice %></p>
|
||||
|
||||
<%= render @user %>
|
||||
|
||||
<div>
|
||||
<%= link_to "Edit this user", edit_user_path(@user) %> |
|
||||
<%= link_to "Back to users", users_path %>
|
||||
|
||||
<%= button_to "Destroy this user", @user, method: :delete %>
|
||||
</div>
|
1
app/views/users/show.json.jbuilder
Normal file
1
app/views/users/show.json.jbuilder
Normal file
|
@ -0,0 +1 @@
|
|||
json.partial! "users/user", user: @user
|
Loading…
Add table
Add a link
Reference in a new issue