Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
522f1cf
Add login function
yuji91 Apr 16, 2021
213d5a3
Add assets
yuji91 Apr 16, 2021
611f10c
Fix show page
yuji91 Apr 16, 2021
8eac748
Merge branch 'test' into answer
yuji91 Apr 19, 2021
c515df1
Merge branch 'test' into answer
yuji91 Apr 19, 2021
5d75251
Merge branch 'test' into answer
yuji91 Apr 22, 2021
ae9bdf5
Merge branch 'test' into answer
yuji91 Apr 22, 2021
9d99a61
Fix: bootstrap 4.5.0を指定
yuji91 Apr 22, 2021
71ad84c
Fix: 説明のコメントを修正
yuji91 Apr 22, 2021
86533f5
Merge branch 'test' into answer
yuji91 Apr 22, 2021
deb4907
Fix flash message
yuji91 Apr 22, 2021
0e9532f
Update Gemfile
yuji91 Apr 22, 2021
fec3109
Merge branch 'test' into answer
yuji91 Apr 22, 2021
5d66a60
Merge branch 'answer' of github.com:runteq/ExamPostApp_Sorcery into a…
yuji91 Apr 22, 2021
598d61d
Update top.scss
yuji91 Apr 22, 2021
544aa66
Merge branch 'test' into answer
yuji91 Apr 23, 2021
a83c7af
Delete useless example
yuji91 Apr 23, 2021
6ebb8c1
Merge branch 'test' into answer
yuji91 May 7, 2021
488551d
rubocop -a
yuji91 May 7, 2021
0d0c1d2
Merge branch 'test' into answer
yuji91 Jun 3, 2021
147d356
Merge branch 'test' into answer
yuji91 Aug 4, 2021
3a89f7f
bundle update ffi
yuji91 Aug 27, 2021
9886354
fix: ignore vendor/
kenchasonakai Oct 5, 2021
76be2bd
Add: コメントを補足
yuji91 Oct 6, 2021
10453c8
Merge pull request #5 from runteq/fix_gitignore
yuji91 Oct 6, 2021
97ae43a
Update .gitignore
yuji91 Feb 15, 2022
cb54488
Update .gitignore
yuji91 Feb 15, 2022
a9791fc
Update .rubocop.yml
kenchasonakai Feb 21, 2022
880044d
Modify: sasscを2.1.0に指定してbundle update
yuji91 Feb 21, 2022
d09b852
Add node-version
yuji91 Feb 24, 2022
44de1b4
Disable turbolinks
yuji91 Feb 24, 2022
b49f53b
Add: sasscのインストール手順を追記
yuji91 Mar 14, 2022
a5fda36
Modify: local appにのみ設定を反映させる
yuji91 Mar 14, 2022
be59b3f
Fix: localオプションの記載を修正
yuji91 Mar 14, 2022
f19ae96
Fix: 記法を統一
yuji91 Mar 14, 2022
11d620f
Merge pull request #6 from runteq/add_info_about_install_sassc
yuji91 Mar 14, 2022
067ce76
Modify: Convert jp to en
yuji91 Mar 18, 2022
7b37f1b
Modify: Convert jp to en
yuji91 Mar 18, 2022
9811c8d
Fix: scaffoldでgenerateしたViewのh1タグが先頭大文字なのでlinkも統一
yuji91 Mar 18, 2022
a687265
Modify: 英語表記に統一
yuji91 Mar 22, 2022
a26ca2d
Modify: ユーザー新規作成のリンクを英語表記にした
yuji91 Mar 22, 2022
5bc9924
Fix: ボタンの文言はデフォルトの表示を利用する
yuji91 Mar 24, 2022
0805ab5
Merge pull request #7 from runteq/master_convert_to_english
yuji91 Mar 28, 2022
e902c03
Merge pull request #9 from runteq/answer_convert_to_english
yuji91 Mar 28, 2022
f08304b
.gitignoreファイルにvenderを追記
Tsuchiya2 Oct 11, 2022
35cca1a
update webdrivers to 5.3
kenchasonakai Aug 17, 2023
441e2af
Merge branch 'master' into answer
kenchasonakai Aug 17, 2023
43efc20
fix: Logout
kenchasonakai Aug 17, 2023
25cdcba
specファイルを更新
kenchasonakai Aug 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@

# Ignore master key for decrypting credentials and more.
/config/master.key

# Ignore vendor
/vendor
/vender

1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
15.14.0
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# This file overrides https://github.com/bbatsov/rubocop/blob/master/config/default.yml

require:
- rubocop-rails

AllCops:
NewCops: enable
Expand Down
3 changes: 1 addition & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
# gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
Expand All @@ -38,6 +36,7 @@ gem 'bootsnap', '>= 1.1.0', require: false

gem 'bootstrap', '~> 4.5.0'
gem 'font-awesome-sass', '~> 5.11.2'
gem 'sassc', '2.1.0'
gem 'jquery-rails'
gem 'sorcery', '0.15.0'

Expand Down
32 changes: 15 additions & 17 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ GEM
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (3.0.0)
childprocess (4.1.0)
coderay (1.1.3)
coffee-rails (4.2.2)
coffee-script (>= 2.2.0)
Expand Down Expand Up @@ -96,7 +96,7 @@ GEM
faraday-excon (1.1.0)
faraday-net_http (1.0.1)
faraday-net_http_persistent (1.1.0)
ffi (1.15.0)
ffi (1.15.5)
font-awesome-sass (5.11.2)
sassc (>= 1.11)
globalid (0.4.2)
Expand All @@ -120,15 +120,15 @@ GEM
marcel (1.0.1)
method_source (1.0.0)
mini_mime (1.1.0)
mini_portile2 (2.5.0)
mini_portile2 (2.8.4)
minitest (5.14.4)
msgpack (1.4.2)
multi_json (1.15.0)
multi_xml (0.6.0)
multipart-post (2.1.1)
nio4r (2.5.7)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
nokogiri (1.13.10)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
oauth (0.5.6)
oauth2 (1.4.7)
Expand All @@ -154,7 +154,7 @@ GEM
pry (>= 0.10.4)
public_suffix (4.0.6)
puma (3.12.6)
racc (1.5.2)
racc (1.7.1)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
Expand Down Expand Up @@ -228,7 +228,7 @@ GEM
ruby-progressbar (1.11.0)
ruby2_keywords (0.0.4)
ruby_dep (1.5.0)
rubyzip (2.3.0)
rubyzip (2.3.2)
sass (3.7.4)
sass-listen (~> 4.0.0)
sass-listen (4.0.0)
Expand All @@ -240,16 +240,17 @@ GEM
sprockets (>= 2.8, < 4.0)
sprockets-rails (>= 2.0, < 4.0)
tilt (>= 1.1, < 3)
sassc (2.4.0)
sassc (2.1.0)
ffi (~> 1.9)
sassc-rails (2.1.2)
railties (>= 4.0.0)
sassc (>= 2.0)
sprockets (> 3.0)
sprockets-rails
tilt
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
sorcery (0.15.0)
bcrypt (~> 3.1)
Expand All @@ -270,9 +271,6 @@ GEM
thor (1.1.0)
thread_safe (0.3.6)
tilt (2.0.10)
turbolinks (5.2.1)
turbolinks-source (~> 5.2)
turbolinks-source (5.2.0)
tzinfo (1.2.9)
thread_safe (~> 0.1)
uglifier (4.2.0)
Expand All @@ -283,10 +281,10 @@ GEM
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webdrivers (4.6.0)
webdrivers (5.3.1)
nokogiri (~> 1.6)
rubyzip (>= 1.3.0)
selenium-webdriver (>= 3.0, < 4.0)
selenium-webdriver (~> 4.0, < 4.11)
websocket-driver (0.7.3)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
Expand Down Expand Up @@ -320,11 +318,11 @@ DEPENDENCIES
rubocop-checkstyle_formatter
rubocop-rails
sass-rails (~> 5.0)
sassc (= 2.1.0)
sorcery (= 0.15.0)
spring
spring-watcher-listen (~> 2.0.0)
sqlite3
turbolinks (~> 5)
tzinfo-data
uglifier (>= 1.3.0)
web-console (>= 3.3.0)
Expand All @@ -334,4 +332,4 @@ RUBY VERSION
ruby 2.6.6p146

BUNDLED WITH
2.1.4
2.4.10
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@

- Ruby 2.6.6 を設定
- プロジェクトで利用するgemをインストール
- `bundle config --local path 'vendor/bundle'`
- `bundle config --local build.sassc -- --disable-march-tune-native`
- `bundle install`
- データベース、テーブルを作成
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
//= require bootstrap-sprockets
//= require rails-ujs
//= require activestorage
//= require turbolinks
//= require_tree .
8 changes: 8 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
class ApplicationController < ActionController::Base
add_flash_types :success, :info, :warning, :danger
before_action :require_login

private

def not_authenticated
redirect_to login_path, warning: 'Please login first.'
end
end
8 changes: 4 additions & 4 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def edit; end

# POST /posts
def create
@post = Post.new(post_params)
@post = current_user.posts.build(post_params)

if @post.save
redirect_to @post, notice: 'Post was successfully created.'
redirect_to @post, success: 'Post was successfully created.'
else
render :new
end
Expand All @@ -31,7 +31,7 @@ def create
# PATCH/PUT /posts/1
def update
if @post.update(post_params)
redirect_to @post, notice: 'Post was successfully updated.'
redirect_to @post, success: 'Post was successfully updated.'
else
render :edit
end
Expand All @@ -40,7 +40,7 @@ def update
# DELETE /posts/1
def destroy
@post.destroy
redirect_to posts_url, notice: 'Post was successfully destroyed.'
redirect_to posts_url, success: 'Post was successfully destroyed.'
end

private
Expand Down
20 changes: 20 additions & 0 deletions app/controllers/user_sessions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class UserSessionsController < ApplicationController
skip_before_action :require_login, only: %i[new create]

def new; end

def create
@user = login(params[:email], params[:password])
if @user
redirect_back_or_to posts_path, success: 'Login successful.'
else
flash.now[:danger] = 'Login failed.'
render :new
end
end

def destroy
logout
redirect_to login_path, success: 'Logout successful.'
end
end
23 changes: 23 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class UsersController < ApplicationController
skip_before_action :require_login, only: %i[new create]

def new
@user = User.new
end

def create
@user = User.new(user_params)
if @user.save
redirect_to login_path, success: 'User was successfully created.'
else
flash.now[:danger] = 'User creation failed.'
render :new
end
end

private

def user_params
params.require(:user).permit(:email, :password, :password_confirmation, :last_name, :first_name)
end
end
4 changes: 4 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
class Post < ApplicationRecord
belongs_to :user

validates :title, presence: true, length: { maximum: 255 }
validates :content, presence: true, length: { maximum: 65_535 }
end
20 changes: 20 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class User < ApplicationRecord
authenticates_with_sorcery!

has_many :posts, dependent: :destroy

validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] }
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }

validates :email, uniqueness: true
validates :email, presence: true
validates :first_name, presence: true, length: { maximum: 255 }
validates :last_name, presence: true, length: { maximum: 255 }

def mine?(object)
# 呼び出し元のオブジェクトのIDを示す self.id を省略した記法。
# @user.mine?(object)のように利用すると、object.user_id と @user.id を比較する。
object.user_id == id
end
end
11 changes: 7 additions & 4 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
</head>

<body>
<%= render 'shared/header' %>
<%# render 'shared/before_login_header' %>
<% if logged_in? %>
<%= render 'shared/header' %>
<% else %>
<%= render 'shared/before_login_header' %>
<% end %>
<%= render 'shared/flash_message' %>
<%= yield %>
<%= render 'shared/footer' %>
Expand Down
6 changes: 4 additions & 2 deletions app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
<td><%= post.title %></td>
<td><%= post.content %></td>
<td><%= link_to 'Show', post %></td>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% if current_user.mine?(post) %>
<td><%= link_to 'Edit', edit_post_path(post) %></td>
<td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
</tr>
<% end %>
</tbody>
Expand Down
5 changes: 3 additions & 2 deletions app/views/posts/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<strong>Content:</strong>
<%= @post.content %>
</p>

<%= link_to 'Edit', edit_post_path(@post) %> |
<% if current_user.mine?(@post) %>
<%= link_to 'Edit', edit_post_path(@post) %> |
<% end %>
<%= link_to 'Back', posts_path %>
2 changes: 1 addition & 1 deletion app/views/shared/_before_login_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ml-auto main-nav align-items-center">
<li class="nav-item">
<%= link_to 'ログイン', login_path, class: 'nav-link' %>
<%= link_to 'Login', login_path, class: 'nav-link' %>
</li>
</ul>
</div>
Expand Down
12 changes: 6 additions & 6 deletions app/views/shared/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@
</a>

<div class="dropdown-menu dropdown-menu-right">
<%= link_to 'Post一覧', posts_path, class: 'dropdown-item' %>
<%= link_to 'Post作成', new_post_path, class: 'dropdown-item' %>
<%= link_to 'List of Posts', posts_path, class: 'dropdown-item' %>
<%= link_to 'New Post', new_post_path, class: 'dropdown-item' %>
</div>
</li>

<li class="nav-item">
<%= link_to 'Like一覧', '#', class: 'nav-link' %>
<%= link_to 'List of Likes', '#', class: 'nav-link' %>
</li>

<li class="nav-item dropdown dropdown-slide">
<a href="#" class="nav-link" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="header-profile">
<%= image_tag 'sample', size: '40x40', class: 'rounded-circle mr15'%>
</a>
<div class="dropdown-menu dropdown-menu-right">
<div class="dropdown-item"><%# "#{current_user.last_name} #{current_user.first_name}" %></div>
<div class="dropdown-item"><%= "#{current_user.last_name} #{current_user.first_name}" %></div>
<div class="dropdown-divider"></div>
<%= link_to 'プロフィール', '#', class: 'dropdown-item' %>
<%= link_to 'ログアウト', '#', class: 'dropdown-item' %>
<%= link_to 'Profile', '#', class: 'dropdown-item' %>
<%= link_to 'Logout', logout_path, method: :delete, class: 'dropdown-item' %>
</div>
</li>
</ul>
Expand Down
25 changes: 25 additions & 0 deletions app/views/user_sessions/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div class="container">
<div class="row">
<div class=" col-md-10 offset-md-1 col-lg-8 offset-lg-2">
<h1>Login</h1>
<%= form_with url: login_path, local: true do |f| %>
<div class="form-group">
<%= f.label :email %>
<%= f.email_field :email, class: 'form-control' %>
</div>
<div class="form-group">
<%= f.label :password %>
<%= f.password_field :password, class: 'form-control' %>
</div>
<div class="actions">
<%= f.submit 'Login', class: 'btn btn-primary' %>
</div>
<% end %>
<div class='text-center'>
<%= link_to 'Signup', new_user_path %>
<a href="#">Forget Password?</a>
</div>
</div>
</div>
</div>

Loading