-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
147 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class UsersController < ApplicationController | ||
def index | ||
@pagy, @users = pagy(User.order(id: :desc), items: 25) | ||
end | ||
|
||
def show | ||
@user = User.find(params[:id]) | ||
end | ||
|
||
def new | ||
@user = User.new | ||
end | ||
|
||
def create | ||
@user = User.new(user_params) | ||
|
||
if @user.save | ||
flash[:success] = 'ユーザを登録しました。' | ||
redirect_to @user | ||
else | ||
flash.now[:danger] = 'ユーザの登録に失敗しました。' | ||
render :new | ||
end | ||
end | ||
|
||
private | ||
|
||
def user_params | ||
params.require(:user).permit(:name, :email, :password, :password_confirmation) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module UsersHelper | ||
def gravatar_url(user, options = { size: 80 }) | ||
gravatar_id = Digest::MD5::hexdigest(user.email.downcase) | ||
size = options[:size] | ||
"https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class User < ApplicationRecord | ||
before_save { self.email.downcase! } | ||
validates :name, presence: true, length: { maximum: 50 } | ||
validates :email, presence: true, length: { maximum: 255 }, | ||
format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i }, | ||
uniqueness: { case_sensitive: false } | ||
has_secure_password | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% if users.any? %> | ||
<ul class="list-unstyled"> | ||
<% users.each do |user| %> | ||
<li class="mb-3 d-flex"> | ||
<img class="rounded me-2" src="<%= gravatar_url(user, { size: 64 }) %>" alt=""> | ||
<div> | ||
<div> | ||
<%= user.name %> | ||
</div> | ||
<div> | ||
<p><%= link_to 'View profile', user_path(user), class: "text-decoration-none" %></p> | ||
</div> | ||
</div> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<%== pagy_bootstrap_nav(@pagy) %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<h1>Users#create</h1> | ||
<p>Find me in app/views/users/create.html.erb</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= render 'users', users: @users %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<div class="text-center"> | ||
<h1>Sign up</h1> | ||
</div> | ||
|
||
<div class="row"> | ||
<div class="col-sm-6 offset-sm-3"> | ||
|
||
<%= form_with(model: @user) do |f| %> | ||
<%= render 'layouts/error_messages', model: f.object %> | ||
|
||
<div class="mb-3"> | ||
<%= f.label :name, 'Name' %> | ||
<%= f.text_field :name, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<%= f.label :email, 'Email' %> | ||
<%= f.email_field :email, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<%= f.label :password, 'Password' %> | ||
<%= f.password_field :password, class: 'form-control' %> | ||
</div> | ||
|
||
<div class="mb-3"> | ||
<%= f.label :password_confirmation, 'Confirmation' %> | ||
<%= f.password_field :password_confirmation, class: 'form-control' %> | ||
</div> | ||
|
||
<%= f.submit 'Sign up', class: 'btn btn-primary w-100' %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<div class="row"> | ||
<aside class="col-sm-4"> | ||
<div class="card"> | ||
<div class="card-header"> | ||
<h3 class="card-title"><%= @user.name %></h3> | ||
</div> | ||
<div class="card-body"> | ||
<img class="rounded img-fluid" src="<%= gravatar_url(@user, { size: 500 }) %>" alt=""> | ||
</div> | ||
</div> | ||
</aside> | ||
<div class="col-sm-8"> | ||
<ul class="nav nav-tabs nav-justified mb-3"> | ||
<li class="nav-item"><a href="#" class="nav-link">Microposts</a></li> | ||
<li class="nav-item"><a href="#" class="nav-link">Followings</a></li> | ||
<li class="nav-item"><a href="#" class="nav-link">Followers</a></li> | ||
</ul> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
require 'pagy/extras/bootstrap' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
Rails.application.routes.draw do | ||
root to: 'tasks#index' | ||
|
||
get 'signup', to: 'users#new' | ||
resources :users, only: [:index, :show, :create] | ||
resources :tasks | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CreateUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
create_table :users do |t| | ||
t.string :name | ||
t.string :email | ||
t.string :password_digest | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.