Skip to content

作業履歴 2017-01-18

概要

2017-01-18の作業内容をまとめています。このジャーナルでは、ユーザー認証機能の実装に関する作業を記録しています。主にログイン・ログアウト機能のルーティングとリンクの設置を行いました。

ユーザー認証機能の構成図

uml diagram

作業内容

ユーザー認証機能の実装

ユーザー認証機能を実装するため、ログイン・ログアウト機能のルーティングとリンクの設置を行いました。これにより、職員がシステムにログインしてアクセス制限のある機能を利用できるようになります。

変更点の概要

  1. ルーティングの設定
  2. ログイン・ログアウト用のルートを追加
  3. RESTfulなリソース設計に基づいたルーティング

  4. ヘッダーへのリンク設置

  5. ログイン・ログアウトリンクをヘッダーに追加
  6. 現在のログイン状態に応じて表示を切り替え

  7. セッション管理

  8. current_staff_memberメソッドの実装
  9. セッションを使用したユーザー状態の管理

技術的詳細

  • current_staff_memberメソッドを使用してログイン状態を確認
  • ログイン・ログアウトリンクの条件分岐表示
  • CSSスタイルの調整によるヘッダーデザインの改善

コミット: 04ebccc

メッセージ

リンクの設置 #3

変更されたファイル

  • M README.md
  • M app/assets/stylesheets/pages/_staff.scss
  • M app/views/shared/staff/_header.html.erb

変更内容

commit 04ebccc1bbd9416ee79f01140afcc4d5593d20cd
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 19:08:47 2017 +0900

    リンクの設置 #3

diff --git a/README.md b/README.md
index 4e8f3cb..50acaf7 100644
--- a/README.md
+++ b/README.md
@@ -347,6 +347,7 @@ git push heroku master
 + セッションとは
 + current_staff_memberメソッドの定義
 + ルーティングの決定
++ リンクの設置

 ### ユーザー認証
 ### ルーティング
diff --git a/app/assets/stylesheets/pages/_staff.scss b/app/assets/stylesheets/pages/_staff.scss
index d28a135..63ec54c 100644
--- a/app/assets/stylesheets/pages/_staff.scss
+++ b/app/assets/stylesheets/pages/_staff.scss
@@ -11,6 +11,19 @@ html, body {
   height: 100%;
 }

+.Header__head {
+  text-align: left;
+}
+
+.logo--staff {
+  color: $color-white;
+}
+
+.login--staff {
+  float: right;
+  color: $very_light_gray;
+}
+
 .Staff {
   &__wrapper {
     position: relative;
@@ -33,6 +46,7 @@ html, body {
   &__header {
     padding: $moderate;
     background-color: $dark_cyan;
+    text-align: left;
     color: $very_light_gray;
     span.logo-mark {
       font-weight: bold;
@@ -51,8 +65,4 @@ html, body {
       margin: 0;
     }
   }
-}
-
-.logo--staff {
-  color: $color-white;
 }
\ No newline at end of file
diff --git a/app/views/shared/staff/_header.html.erb b/app/views/shared/staff/_header.html.erb
index 861f549..e28bfeb 100644
--- a/app/views/shared/staff/_header.html.erb
+++ b/app/views/shared/staff/_header.html.erb
@@ -10,4 +10,10 @@
       <li class="Menu__item"><a href="#"></a></li>
     </ul>
   </nav>
+  <%= if current_staff_member
+        link_to 'ログアウト', :staff_session, method:delete, class: 'login--staff'
+      else
+        link_to 'ログイン', :staff_login, class: 'login--staff'
+      end
+    %>
 </header>
\ No newline at end of file

コミット: 21428ac

メッセージ

ルーティングの決定 #3

変更されたファイル

  • M README.md
  • M config/routes.rb

変更内容

commit 21428ac4c63d3ee3c35dcec6cf04ee6b5058c44b
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 18:52:58 2017 +0900

    ルーティングの決定 #3

diff --git a/README.md b/README.md
index 7f19c0c..4e8f3cb 100644
--- a/README.md
+++ b/README.md
@@ -346,6 +346,7 @@ git push heroku master
 #### セッション
 + セッションとは
 + current_staff_memberメソッドの定義
++ ルーティングの決定

 ### ユーザー認証
 ### ルーティング
diff --git a/config/routes.rb b/config/routes.rb
index e26d28b..17026a1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,8 +1,28 @@
+# == Route Map
+#
+#                   Prefix Verb   URI Pattern                         Controller#Action
+#     errors_routing_error GET    /errors/routing_error(.:format)     errors#routing_error
+#               staff_root GET    /staff(.:format)                    staff/top#index
+#              staff_login GET    /staff/login(.:format)              staff/sessions#new
+#            staff_session POST   /staff/session(.:format)            staff/sessions#create
+#                          DELETE /staff/session(.:format)            staff/sessions#destroy
+#               admin_root GET    /admin(.:format)                    admin/top#index
+#            customer_root GET    /customer(.:format)                 customer/top#index
+#   customer_article_index GET    /customer/article/index(.:format)   customer/article#index
+#  customer_campaign_index GET    /customer/campaign/index(.:format)  customer/campaign#index
+# customer_campaign_submit GET    /customer/campaign_submit(.:format) customer/campaign#submit
+#                     root GET    /                                   errors#routing_error
+#                          GET    /*anything(.:format)                errors#routing_error
+#
+
 Rails.application.routes.draw do
   get 'errors/routing_error'

   namespace :staff do
-    root 'top#index'
+    root   'top#index'
+    get    'login'   => 'sessions#new', as: :login
+    post   'session' => 'sessions#create', as: :session
+    delete 'session' => 'sessions#destroy'
   end

   namespace :admin do

コミット: c673afe

メッセージ

current_staff_memberメソッドの定義 #3

変更されたファイル

  • M README.md
  • A app/controllers/staff/base.rb
  • M app/controllers/staff/top_controller.rb

変更内容

commit c673afe22c1a10f3f6bd12ee9fe9666b10c9b479
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 18:48:46 2017 +0900

    current_staff_memberメソッドの定義 #3

diff --git a/README.md b/README.md
index f703916..7f19c0c 100644
--- a/README.md
+++ b/README.md
@@ -345,6 +345,7 @@ git push heroku master

 #### セッション
 + セッションとは
++ current_staff_memberメソッドの定義

 ### ユーザー認証
 ### ルーティング
diff --git a/app/controllers/staff/base.rb b/app/controllers/staff/base.rb
new file mode 100644
index 0000000..ecfda96
--- /dev/null
+++ b/app/controllers/staff/base.rb
@@ -0,0 +1,11 @@
+class Staff::Base < ApplicationController
+  private
+  def current_staff_member
+    if session[:staff_member_id]
+      @current_staff_member ||=
+          StaffMember.find_by(id: session[:staff_member_id])
+    end
+  end
+
+  helper_method :current_staff_member
+end
\ No newline at end of file
diff --git a/app/controllers/staff/top_controller.rb b/app/controllers/staff/top_controller.rb
index 290f42f..6645b22 100644
--- a/app/controllers/staff/top_controller.rb
+++ b/app/controllers/staff/top_controller.rb
@@ -1,4 +1,4 @@
-class Staff::TopController < ApplicationController
+class Staff::TopController < Staff::Base
   def index
     render action: 'index'
   end

構造変更

uml diagram

コミット: 7585fb2

メッセージ

セッションとは #3

変更されたファイル

  • M README.md

変更内容

commit 7585fb21a6edc2ab1610e6f53476eb67ec0d1fe3
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 18:43:17 2017 +0900

    セッションとは #3

diff --git a/README.md b/README.md
index de625b1..f703916 100644
--- a/README.md
+++ b/README.md
@@ -344,6 +344,7 @@ git push heroku master
 + シードデータ投入

 #### セッション
++ セッションとは

 ### ユーザー認証
 ### ルーティング

コミット: 0d08431

メッセージ

シードデータ投入 #3

変更されたファイル

  • M README.md
  • A db/seed/development/staff_members.rb
  • M db/seeds.rb

変更内容

commit 0d084315300d9334ffd55d2e87fe570f89690630
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 18:39:32 2017 +0900

    シードデータ投入 #3

diff --git a/README.md b/README.md
index f6896d0..de625b1 100644
--- a/README.md
+++ b/README.md
@@ -341,6 +341,7 @@ git push heroku master
 + モデルの基礎知識
 + 索引用メールアドレス
 + ハッシュ関数
++ シードデータ投入

 #### セッション

diff --git a/db/seed/development/staff_members.rb b/db/seed/development/staff_members.rb
new file mode 100644
index 0000000..7156a40
--- /dev/null
+++ b/db/seed/development/staff_members.rb
@@ -0,0 +1,9 @@
+StaffMember.create(
+               email: 'taro@example.com',
+               family_name: '山田',
+               given_name: '太郎',
+               family_name_kana: 'ヤマダ',
+               given_name_kana: 'タロウ',
+               password: 'password',
+               start_date: Date.today
+)
\ No newline at end of file
diff --git a/db/seeds.rb b/db/seeds.rb
index 1beea2a..3549c1d 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -1,7 +1,16 @@
 # This file should contain all the record creation needed to seed the database with its default values.
-# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
+# The data can then be loaded with the rails db:seed command (or created alongsidtse the database with db:setup).
 #
 # Examples:
 #
+
 #   movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
 #   Character.create(name: 'Luke', movie: movies.first)
+table_names = %w(staff_members)
+table_names.each do |table_name|
+  path = Rails.root.join('db','seed',Rails.env, "#{table_name}.rb")
+  if File.exist?(path)
+    puts "Creating #{table_name}...."
+    require(path)
+  end
+end
\ No newline at end of file

コミット: aab3d61

メッセージ

ハッシュ関数 #3

変更されたファイル

  • M .idea/.rakeTasks
  • M Gemfile
  • M Gemfile.lock
  • M README.md
  • M app/models/staff_member.rb
  • M baukis-kai.iml
  • M spec/models/staff_member_spec.rb

変更内容

commit aab3d61d1eff766cfa50cc2a5e76901392dc4e5e
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 18:09:49 2017 +0900

    ハッシュ関数 #3

diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks
index ef72890..9cf55a4 100644
--- a/.idea/.rakeTasks
+++ b/.idea/.rakeTasks
@@ -4,4 +4,4 @@ You are allowed to:
 1. Remove rake task
 2. Add existing rake tasks
 To add existing rake tasks automatically delete this file and reload the project.
---><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="List versions of all Rails frameworks and the environment" fullCmd="about" taksId="about" /><RakeGroup description="" fullCmd="" taksId="app"><RakeTask description="Applies the template supplied by LOCATION=(/path/to/template) or URL" fullCmd="app:template" taksId="template" /><RakeTask description="Update configs and some other initially generated files (or use just update:configs or update:bin)" fullCmd="app:update" taksId="update" /><RakeGroup description="" fullCmd="" taksId="templates"><RakeTask description="" fullCmd="app:templates:copy" taksId="copy" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="update"><RakeTask description="" fullCmd="app:update:bin" taksId="bin" /><RakeTask description="" fullCmd="app:update:configs" taksId="configs" /><RakeTask description="" fullCmd="app:update:upgrade_guide_info" taksId="upgrade_guide_info" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="assets"><RakeTask description="Remove old compiled assets" fullCmd="assets:clean[keep]" taksId="clean[keep]" /><RakeTask description="Remove compiled assets" fullCmd="assets:clobber" taksId="clobber" /><RakeTask description="Load asset compile environment" fullCmd="assets:environment" taksId="environment" /><RakeTask description="Compile all the assets named in config.assets.precompile" fullCmd="assets:precompile" taksId="precompile" /><RakeTask description="" fullCmd="assets:clean" taksId="clean" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="cache_digests"><RakeTask description="Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)" fullCmd="cache_digests:dependencies" taksId="dependencies" /><RakeTask description="Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)" fullCmd="cache_digests:nested_dependencies" taksId="nested_dependencies" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="db"><RakeTask description="Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases" fullCmd="db:create" taksId="create" /><RakeTask description="Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases" fullCmd="db:drop" taksId="drop" /><RakeGroup description="" fullCmd="" taksId="environment"><RakeTask description="Set the environment value for the database" fullCmd="db:environment:set" taksId="set" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="fixtures"><RakeTask description="Loads fixtures into the current environment's database" fullCmd="db:fixtures:load" taksId="load" /><RakeTask description="" fullCmd="db:fixtures:identify" taksId="identify" /></RakeGroup><RakeTask description="Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)" fullCmd="db:migrate" taksId="migrate" /><RakeGroup description="" fullCmd="" taksId="migrate"><RakeTask description="Display status of migrations" fullCmd="db:migrate:status" taksId="status" /><RakeTask description="" fullCmd="db:migrate:down" taksId="down" /><RakeTask description="" fullCmd="db:migrate:redo" taksId="redo" /><RakeTask description="" fullCmd="db:migrate:reset" taksId="reset" /><RakeTask description="" fullCmd="db:migrate:up" taksId="up" /></RakeGroup><RakeTask description="Rolls the schema back to the previous version (specify steps w/ STEP=n)" fullCmd="db:rollback" taksId="rollback" /><RakeGroup description="" fullCmd="" taksId="schema"><RakeGroup description="" fullCmd="" taksId="cache"><RakeTask description="Clears a db/schema_cache.dump file" fullCmd="db:schema:cache:clear" taksId="clear" /><RakeTask description="Creates a db/schema_cache.dump file" fullCmd="db:schema:cache:dump" taksId="dump" /></RakeGroup><RakeTask description="Creates a db/schema.rb file that is portable against any DB supported by Active Record" fullCmd="db:schema:dump" taksId="dump" /><RakeTask description="Loads a schema.rb file into the database" fullCmd="db:schema:load" taksId="load" /><RakeTask description="" fullCmd="db:schema:load_if_ruby" taksId="load_if_ruby" /></RakeGroup><RakeTask description="Loads the seed data from db/seeds.rb" fullCmd="db:seed" taksId="seed" /><RakeTask description="Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)" fullCmd="db:setup" taksId="setup" /><RakeGroup description="" fullCmd="" taksId="structure"><RakeTask description="Dumps the database structure to db/structure.sql" fullCmd="db:structure:dump" taksId="dump" /><RakeTask description="Recreates the databases from the structure.sql file" fullCmd="db:structure:load" taksId="load" /><RakeTask description="" fullCmd="db:structure:load_if_sql" taksId="load_if_sql" /></RakeGroup><RakeTask description="Retrieves the current schema version number" fullCmd="db:version" taksId="version" /><RakeTask description="" fullCmd="db:_dump" taksId="_dump" /><RakeTask description="" fullCmd="db:abort_if_pending_migrations" taksId="abort_if_pending_migrations" /><RakeTask description="" fullCmd="db:charset" taksId="charset" /><RakeTask description="" fullCmd="db:check_protected_environments" taksId="check_protected_environments" /><RakeTask description="" fullCmd="db:collation" taksId="collation" /><RakeGroup description="" fullCmd="" taksId="create"><RakeTask description="" fullCmd="db:create:all" taksId="all" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="drop"><RakeTask description="" fullCmd="db:drop:_unsafe" taksId="_unsafe" /><RakeTask description="" fullCmd="db:drop:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="db:forward" taksId="forward" /><RakeTask description="" fullCmd="db:load_config" taksId="load_config" /><RakeTask description="" fullCmd="db:purge" taksId="purge" /><RakeGroup description="" fullCmd="" taksId="purge"><RakeTask description="" fullCmd="db:purge:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="db:reset" taksId="reset" /><RakeGroup description="" fullCmd="" taksId="test"><RakeTask description="" fullCmd="db:test:clone" taksId="clone" /><RakeTask description="" fullCmd="db:test:clone_schema" taksId="clone_schema" /><RakeTask description="" fullCmd="db:test:clone_structure" taksId="clone_structure" /><RakeTask description="" fullCmd="db:test:deprecated" taksId="deprecated" /><RakeTask description="" fullCmd="db:test:load" taksId="load" /><RakeTask description="" fullCmd="db:test:load_schema" taksId="load_schema" /><RakeTask description="" fullCmd="db:test:load_structure" taksId="load_structure" /><RakeTask description="" fullCmd="db:test:prepare" taksId="prepare" /><RakeTask description="" fullCmd="db:test:purge" taksId="purge" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="dev"><RakeTask description="Toggle development mode caching on/off" fullCmd="dev:cache" taksId="cache" /></RakeGroup><RakeTask description="Generate an Entity-Relationship Diagram based on your models" fullCmd="erd" taksId="erd" /><RakeTask description="Print out all defined initializers in the order they are invoked by Rails" fullCmd="initializers" taksId="initializers" /><RakeGroup description="" fullCmd="" taksId="log"><RakeTask description="Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)" fullCmd="log:clear" taksId="clear" /></RakeGroup><RakeTask description="Prints out your Rack middleware stack" fullCmd="middleware" taksId="middleware" /><RakeTask description="Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" fullCmd="notes" taksId="notes" /><RakeGroup description="" fullCmd="" taksId="notes"><RakeTask description="Enumerate a custom annotation, specify with ANNOTATION=CUSTOM" fullCmd="notes:custom" taksId="custom" /><RakeTask description="" fullCmd="notes:fixme" taksId="fixme" /><RakeTask description="" fullCmd="notes:optimize" taksId="optimize" /><RakeTask description="" fullCmd="notes:todo" taksId="todo" /></RakeGroup><RakeTask description="Restart app by touching tmp/restart.txt" fullCmd="restart" taksId="restart" /><RakeTask description="Print out all defined routes in match order, with names" fullCmd="routes" taksId="routes" /><RakeTask description="Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)" fullCmd="secret" taksId="secret" /><RakeTask description="Run all specs in spec directory (excluding plugin specs)" fullCmd="spec" taksId="spec" /><RakeTask description="Report code statistics (KLOCs, etc) from the application or engine" fullCmd="stats" taksId="stats" /><RakeTask description="Runs all tests in test folder" fullCmd="test" taksId="test" /><RakeGroup description="" fullCmd="" taksId="test"><RakeTask description="Run tests quickly, but also reset db" fullCmd="test:db" taksId="db" /><RakeTask description="" fullCmd="test:controllers" taksId="controllers" /><RakeTask description="" fullCmd="test:functionals" taksId="functionals" /><RakeTask description="" fullCmd="test:generators" taksId="generators" /><RakeTask description="" fullCmd="test:helpers" taksId="helpers" /><RakeTask description="" fullCmd="test:integration" taksId="integration" /><RakeTask description="" fullCmd="test:jobs" taksId="jobs" /><RakeTask description="" fullCmd="test:mailers" taksId="mailers" /><RakeTask description="" fullCmd="test:models" taksId="models" /><RakeTask description="" fullCmd="test:prepare" taksId="prepare" /><RakeTask description="" fullCmd="test:run" taksId="run" /><RakeTask description="" fullCmd="test:units" taksId="units" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="time"><RakeTask description="List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)" fullCmd="time:zones[country_or_offset]" taksId="zones[country_or_offset]" /><RakeTask description="" fullCmd="time:zones" taksId="zones" /><RakeGroup description="" fullCmd="" taksId="zones"><RakeTask description="" fullCmd="time:zones:all" taksId="all" /><RakeTask description="" fullCmd="time:zones:local" taksId="local" /><RakeTask description="" fullCmd="time:zones:us" taksId="us" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="tmp"><RakeTask description="Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)" fullCmd="tmp:clear" taksId="clear" /><RakeTask description="Creates tmp directories for cache, sockets, and pids" fullCmd="tmp:create" taksId="create" /><RakeGroup description="" fullCmd="" taksId="cache"><RakeTask description="" fullCmd="tmp:cache:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="pids"><RakeTask description="" fullCmd="tmp:pids:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="sockets"><RakeTask description="" fullCmd="tmp:sockets:clear" taksId="clear" /></RakeGroup></RakeGroup><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="environment" taksId="environment" /><RakeGroup description="" fullCmd="" taksId="erd"><RakeTask description="" fullCmd="erd:generate" taksId="generate" /><RakeTask description="" fullCmd="erd:load_models" taksId="load_models" /><RakeTask description="" fullCmd="erd:options" taksId="options" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="rails"><RakeTask description="" fullCmd="rails:template" taksId="template" /><RakeGroup description="" fullCmd="" taksId="templates"><RakeTask description="" fullCmd="rails:templates:copy" taksId="copy" /></RakeGroup><RakeTask description="" fullCmd="rails:update" taksId="update" /><RakeGroup description="" fullCmd="" taksId="update"><RakeTask description="" fullCmd="rails:update:bin" taksId="bin" /><RakeTask description="" fullCmd="rails:update:configs" taksId="configs" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="railties"><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="" fullCmd="railties:install:migrations" taksId="migrations" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="spec"><RakeTask description="" fullCmd="spec:prepare" taksId="prepare" /><RakeTask description="" fullCmd="spec:statsetup" taksId="statsetup" /></RakeGroup><RakeTask description="" fullCmd="tmp" taksId="tmp" /><RakeTask description="" fullCmd="tmp/cache" taksId="tmp/cache" /><RakeTask description="" fullCmd="tmp/cache/assets" taksId="tmp/cache/assets" /><RakeTask description="" fullCmd="tmp/pids" taksId="tmp/pids" /><RakeTask description="" fullCmd="tmp/sockets" taksId="tmp/sockets" /></RakeGroup></Settings>
+--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="List versions of all Rails frameworks and the environment" fullCmd="about" taksId="about" /><RakeTask description="Add schema information (as comments) to model and fixture files" fullCmd="annotate_models" taksId="annotate_models" /><RakeTask description="Adds the route map to routes.rb" fullCmd="annotate_routes" taksId="annotate_routes" /><RakeGroup description="" fullCmd="" taksId="app"><RakeTask description="Applies the template supplied by LOCATION=(/path/to/template) or URL" fullCmd="app:template" taksId="template" /><RakeTask description="Update configs and some other initially generated files (or use just update:configs or update:bin)" fullCmd="app:update" taksId="update" /><RakeGroup description="" fullCmd="" taksId="templates"><RakeTask description="" fullCmd="app:templates:copy" taksId="copy" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="update"><RakeTask description="" fullCmd="app:update:bin" taksId="bin" /><RakeTask description="" fullCmd="app:update:configs" taksId="configs" /><RakeTask description="" fullCmd="app:update:upgrade_guide_info" taksId="upgrade_guide_info" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="assets"><RakeTask description="Remove old compiled assets" fullCmd="assets:clean[keep]" taksId="clean[keep]" /><RakeTask description="Remove compiled assets" fullCmd="assets:clobber" taksId="clobber" /><RakeTask description="Load asset compile environment" fullCmd="assets:environment" taksId="environment" /><RakeTask description="Compile all the assets named in config.assets.precompile" fullCmd="assets:precompile" taksId="precompile" /><RakeTask description="" fullCmd="assets:clean" taksId="clean" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="cache_digests"><RakeTask description="Lookup first-level dependencies for TEMPLATE (like messages/show or comments/_comment.html)" fullCmd="cache_digests:dependencies" taksId="dependencies" /><RakeTask description="Lookup nested dependencies for TEMPLATE (like messages/show or comments/_comment.html)" fullCmd="cache_digests:nested_dependencies" taksId="nested_dependencies" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="db"><RakeTask description="Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to creating the development and test databases" fullCmd="db:create" taksId="create" /><RakeTask description="Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config). Without RAILS_ENV or when RAILS_ENV is development, it defaults to dropping the development and test databases" fullCmd="db:drop" taksId="drop" /><RakeGroup description="" fullCmd="" taksId="environment"><RakeTask description="Set the environment value for the database" fullCmd="db:environment:set" taksId="set" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="fixtures"><RakeTask description="Loads fixtures into the current environment's database" fullCmd="db:fixtures:load" taksId="load" /><RakeTask description="" fullCmd="db:fixtures:identify" taksId="identify" /></RakeGroup><RakeTask description="Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)" fullCmd="db:migrate" taksId="migrate" /><RakeGroup description="" fullCmd="" taksId="migrate"><RakeTask description="Display status of migrations" fullCmd="db:migrate:status" taksId="status" /><RakeTask description="" fullCmd="db:migrate:change" taksId="change" /><RakeTask description="" fullCmd="db:migrate:down" taksId="down" /><RakeTask description="" fullCmd="db:migrate:redo" taksId="redo" /><RakeTask description="" fullCmd="db:migrate:reset" taksId="reset" /><RakeTask description="" fullCmd="db:migrate:up" taksId="up" /></RakeGroup><RakeTask description="Rolls the schema back to the previous version (specify steps w/ STEP=n)" fullCmd="db:rollback" taksId="rollback" /><RakeGroup description="" fullCmd="" taksId="schema"><RakeGroup description="" fullCmd="" taksId="cache"><RakeTask description="Clears a db/schema_cache.dump file" fullCmd="db:schema:cache:clear" taksId="clear" /><RakeTask description="Creates a db/schema_cache.dump file" fullCmd="db:schema:cache:dump" taksId="dump" /></RakeGroup><RakeTask description="Creates a db/schema.rb file that is portable against any DB supported by Active Record" fullCmd="db:schema:dump" taksId="dump" /><RakeTask description="Loads a schema.rb file into the database" fullCmd="db:schema:load" taksId="load" /><RakeTask description="" fullCmd="db:schema:load_if_ruby" taksId="load_if_ruby" /></RakeGroup><RakeTask description="Loads the seed data from db/seeds.rb" fullCmd="db:seed" taksId="seed" /><RakeTask description="Creates the database, loads the schema, and initializes with the seed data (use db:reset to also drop the database first)" fullCmd="db:setup" taksId="setup" /><RakeGroup description="" fullCmd="" taksId="structure"><RakeTask description="Dumps the database structure to db/structure.sql" fullCmd="db:structure:dump" taksId="dump" /><RakeTask description="Recreates the databases from the structure.sql file" fullCmd="db:structure:load" taksId="load" /><RakeTask description="" fullCmd="db:structure:load_if_sql" taksId="load_if_sql" /></RakeGroup><RakeTask description="Retrieves the current schema version number" fullCmd="db:version" taksId="version" /><RakeTask description="" fullCmd="db:_dump" taksId="_dump" /><RakeTask description="" fullCmd="db:abort_if_pending_migrations" taksId="abort_if_pending_migrations" /><RakeTask description="" fullCmd="db:charset" taksId="charset" /><RakeTask description="" fullCmd="db:check_protected_environments" taksId="check_protected_environments" /><RakeTask description="" fullCmd="db:collation" taksId="collation" /><RakeGroup description="" fullCmd="" taksId="create"><RakeTask description="" fullCmd="db:create:all" taksId="all" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="drop"><RakeTask description="" fullCmd="db:drop:_unsafe" taksId="_unsafe" /><RakeTask description="" fullCmd="db:drop:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="db:forward" taksId="forward" /><RakeTask description="" fullCmd="db:load_config" taksId="load_config" /><RakeTask description="" fullCmd="db:purge" taksId="purge" /><RakeGroup description="" fullCmd="" taksId="purge"><RakeTask description="" fullCmd="db:purge:all" taksId="all" /></RakeGroup><RakeTask description="" fullCmd="db:reset" taksId="reset" /><RakeGroup description="" fullCmd="" taksId="test"><RakeTask description="" fullCmd="db:test:clone" taksId="clone" /><RakeTask description="" fullCmd="db:test:clone_schema" taksId="clone_schema" /><RakeTask description="" fullCmd="db:test:clone_structure" taksId="clone_structure" /><RakeTask description="" fullCmd="db:test:deprecated" taksId="deprecated" /><RakeTask description="" fullCmd="db:test:load" taksId="load" /><RakeTask description="" fullCmd="db:test:load_schema" taksId="load_schema" /><RakeTask description="" fullCmd="db:test:load_structure" taksId="load_structure" /><RakeTask description="" fullCmd="db:test:prepare" taksId="prepare" /><RakeTask description="" fullCmd="db:test:purge" taksId="purge" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="dev"><RakeTask description="Toggle development mode caching on/off" fullCmd="dev:cache" taksId="cache" /></RakeGroup><RakeTask description="Generate an Entity-Relationship Diagram based on your models" fullCmd="erd" taksId="erd" /><RakeTask description="Print out all defined initializers in the order they are invoked by Rails" fullCmd="initializers" taksId="initializers" /><RakeGroup description="" fullCmd="" taksId="log"><RakeTask description="Truncates all/specified *.log files in log/ to zero bytes (specify which logs with LOGS=test,development)" fullCmd="log:clear" taksId="clear" /></RakeGroup><RakeTask description="Prints out your Rack middleware stack" fullCmd="middleware" taksId="middleware" /><RakeTask description="Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" fullCmd="notes" taksId="notes" /><RakeGroup description="" fullCmd="" taksId="notes"><RakeTask description="Enumerate a custom annotation, specify with ANNOTATION=CUSTOM" fullCmd="notes:custom" taksId="custom" /><RakeTask description="" fullCmd="notes:fixme" taksId="fixme" /><RakeTask description="" fullCmd="notes:optimize" taksId="optimize" /><RakeTask description="" fullCmd="notes:todo" taksId="todo" /></RakeGroup><RakeTask description="Remove schema information from model and fixture files" fullCmd="remove_annotation" taksId="remove_annotation" /><RakeTask description="Removes the route map from routes.rb" fullCmd="remove_routes" taksId="remove_routes" /><RakeTask description="Restart app by touching tmp/restart.txt" fullCmd="restart" taksId="restart" /><RakeTask description="Print out all defined routes in match order, with names" fullCmd="routes" taksId="routes" /><RakeTask description="Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie sessions)" fullCmd="secret" taksId="secret" /><RakeTask description="Run all specs in spec directory (excluding plugin specs)" fullCmd="spec" taksId="spec" /><RakeGroup description="" fullCmd="" taksId="spec"><RakeTask description="Run the code examples in spec/models" fullCmd="spec:models" taksId="models" /><RakeTask description="" fullCmd="spec:prepare" taksId="prepare" /><RakeTask description="" fullCmd="spec:statsetup" taksId="statsetup" /></RakeGroup><RakeTask description="Report code statistics (KLOCs, etc) from the application or engine" fullCmd="stats" taksId="stats" /><RakeTask description="Runs all tests in test folder" fullCmd="test" taksId="test" /><RakeGroup description="" fullCmd="" taksId="test"><RakeTask description="Run tests quickly, but also reset db" fullCmd="test:db" taksId="db" /><RakeTask description="" fullCmd="test:controllers" taksId="controllers" /><RakeTask description="" fullCmd="test:functionals" taksId="functionals" /><RakeTask description="" fullCmd="test:generators" taksId="generators" /><RakeTask description="" fullCmd="test:helpers" taksId="helpers" /><RakeTask description="" fullCmd="test:integration" taksId="integration" /><RakeTask description="" fullCmd="test:jobs" taksId="jobs" /><RakeTask description="" fullCmd="test:mailers" taksId="mailers" /><RakeTask description="" fullCmd="test:models" taksId="models" /><RakeTask description="" fullCmd="test:prepare" taksId="prepare" /><RakeTask description="" fullCmd="test:run" taksId="run" /><RakeTask description="" fullCmd="test:units" taksId="units" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="time"><RakeTask description="List all time zones, list by two-letter country code (`rails time:zones[US]`), or list by UTC offset (`rails time:zones[-8]`)" fullCmd="time:zones[country_or_offset]" taksId="zones[country_or_offset]" /><RakeTask description="" fullCmd="time:zones" taksId="zones" /><RakeGroup description="" fullCmd="" taksId="zones"><RakeTask description="" fullCmd="time:zones:all" taksId="all" /><RakeTask description="" fullCmd="time:zones:local" taksId="local" /><RakeTask description="" fullCmd="time:zones:us" taksId="us" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="tmp"><RakeTask description="Clear cache and socket files from tmp/ (narrow w/ tmp:cache:clear, tmp:sockets:clear)" fullCmd="tmp:clear" taksId="clear" /><RakeTask description="Creates tmp directories for cache, sockets, and pids" fullCmd="tmp:create" taksId="create" /><RakeGroup description="" fullCmd="" taksId="cache"><RakeTask description="" fullCmd="tmp:cache:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="pids"><RakeTask description="" fullCmd="tmp:pids:clear" taksId="clear" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="sockets"><RakeTask description="" fullCmd="tmp:sockets:clear" taksId="clear" /></RakeGroup></RakeGroup><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="environment" taksId="environment" /><RakeGroup description="" fullCmd="" taksId="erd"><RakeTask description="" fullCmd="erd:generate" taksId="generate" /><RakeTask description="" fullCmd="erd:load_models" taksId="load_models" /><RakeTask description="" fullCmd="erd:options" taksId="options" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="rails"><RakeTask description="" fullCmd="rails:template" taksId="template" /><RakeGroup description="" fullCmd="" taksId="templates"><RakeTask description="" fullCmd="rails:templates:copy" taksId="copy" /></RakeGroup><RakeTask description="" fullCmd="rails:update" taksId="update" /><RakeGroup description="" fullCmd="" taksId="update"><RakeTask description="" fullCmd="rails:update:bin" taksId="bin" /><RakeTask description="" fullCmd="rails:update:configs" taksId="configs" /></RakeGroup></RakeGroup><RakeGroup description="" fullCmd="" taksId="railties"><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="" fullCmd="railties:install:migrations" taksId="migrations" /></RakeGroup></RakeGroup><RakeTask description="" fullCmd="set_annotation_options" taksId="set_annotation_options" /><RakeTask description="" fullCmd="tmp" taksId="tmp" /><RakeTask description="" fullCmd="tmp/cache" taksId="tmp/cache" /><RakeTask description="" fullCmd="tmp/cache/assets" taksId="tmp/cache/assets" /><RakeTask description="" fullCmd="tmp/pids" taksId="tmp/pids" /><RakeTask description="" fullCmd="tmp/sockets" taksId="tmp/sockets" /></RakeGroup></Settings>
diff --git a/Gemfile b/Gemfile
index b46c6fa..0ef0810 100644
--- a/Gemfile
+++ b/Gemfile
@@ -31,7 +31,7 @@ gem 'jbuilder', '~> 2.5'
 # Use Redis adapter to run Action Cable in production
 # gem 'redis', '~> 3.0'
 # Use ActiveModel has_secure_password
-# gem 'bcrypt', '~> 3.1.7'
+gem 'bcrypt', '~> 3.1.7'

 # Use Capistrano for deployment
 # gem 'capistrano-rails', group: :development
diff --git a/Gemfile.lock b/Gemfile.lock
index f553bc1..46d4a3a 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -46,6 +46,7 @@ GEM
     arel (7.1.4)
     autoprefixer-rails (6.6.1)
       execjs
+    bcrypt (3.1.11)
     better_errors (2.1.1)
       coderay (>= 1.0.0)
       erubis (>= 2.6.6)
@@ -294,6 +295,7 @@ PLATFORMS

 DEPENDENCIES
   annotate
+  bcrypt (~> 3.1.7)
   better_errors
   binding_of_caller
   bootstrap-sass (~> 3.3.6)
diff --git a/README.md b/README.md
index dadbfa0..f6896d0 100644
--- a/README.md
+++ b/README.md
@@ -340,6 +340,7 @@ git push heroku master
 #### モデル
 + モデルの基礎知識
 + 索引用メールアドレス
++ ハッシュ関数

 #### セッション

diff --git a/app/models/staff_member.rb b/app/models/staff_member.rb
index 0910503..85c873d 100644
--- a/app/models/staff_member.rb
+++ b/app/models/staff_member.rb
@@ -26,4 +26,12 @@ class StaffMember < ApplicationRecord
   before_validation do
     self.email_for_index = email.downcase if email
   end
+
+  def password=(raw_password)
+    if raw_password.kind_of?(String)
+      self.hashed_password = BCrypt::Password.create(raw_password)
+    elsif raw_password.nil?
+      self.hashed_password = nil
+    end
+  end
 end
diff --git a/baukis-kai.iml b/baukis-kai.iml
index ec2b1a1..7d95f8d 100644
--- a/baukis-kai.iml
+++ b/baukis-kai.iml
@@ -34,6 +34,7 @@
     <orderEntry type="library" scope="PROVIDED" name="annotate (v2.6.5, rbenv: 2.4.0) [gem]" level="application" />
     <orderEntry type="library" scope="PROVIDED" name="arel (v7.1.4, rbenv: 2.4.0) [gem]" level="application" />
     <orderEntry type="library" scope="PROVIDED" name="autoprefixer-rails (v6.6.1, rbenv: 2.4.0) [gem]" level="application" />
+    <orderEntry type="library" scope="PROVIDED" name="bcrypt (v3.1.11, rbenv: 2.4.0) [gem]" level="application" />
     <orderEntry type="library" scope="PROVIDED" name="better_errors (v2.1.1, rbenv: 2.4.0) [gem]" level="application" />
     <orderEntry type="library" scope="PROVIDED" name="binding_of_caller (v0.7.2, rbenv: 2.4.0) [gem]" level="application" />
     <orderEntry type="library" scope="PROVIDED" name="bootstrap-sass (v3.3.7, rbenv: 2.4.0) [gem]" level="application" />
diff --git a/spec/models/staff_member_spec.rb b/spec/models/staff_member_spec.rb
index c26bb75..21f5c12 100644
--- a/spec/models/staff_member_spec.rb
+++ b/spec/models/staff_member_spec.rb
@@ -25,5 +25,20 @@
 require 'rails_helper'

 RSpec.describe StaffMember, type: :model do
-  pending "add some examples to (or delete) #{__FILE__}"
+  describe '#password=' do
+    # 文字列を与えると、hashed_passwordは長さ60の文字列になる
+    it 'is a string of length 60 of hashed_password when giving a string' do
+      member = StaffMember.new
+      member.password = 'baukis'
+      expect(member.hashed_password).to be_kind_of(String)
+      expect(member.hashed_password.size).to eq(60)
+    end
+
+    # nilを与えると、hashed_passwordはnilになる
+    it 'is nil of hashed_password when giving a nil' do
+      member = StaffMember.new(hashed_password: 'x')
+      member.password = nil
+      expect(member.hashed_password).to be_nil
+    end
+  end
 end

構造変更

uml diagram

コミット: 52549cb

メッセージ

索引用メールアドレス #3

変更されたファイル

  • M README.md
  • M app/models/staff_member.rb

変更内容

commit 52549cb5eb0147c6e810dfc610d52783104ae440
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 17:54:16 2017 +0900

    索引用メールアドレス #3

diff --git a/README.md b/README.md
index 5e1ff05..dadbfa0 100644
--- a/README.md
+++ b/README.md
@@ -339,6 +339,7 @@ git push heroku master

 #### モデル
 + モデルの基礎知識
++ 索引用メールアドレス

 #### セッション

diff --git a/app/models/staff_member.rb b/app/models/staff_member.rb
index 409a66f..0910503 100644
--- a/app/models/staff_member.rb
+++ b/app/models/staff_member.rb
@@ -23,4 +23,7 @@
 #

 class StaffMember < ApplicationRecord
+  before_validation do
+    self.email_for_index = email.downcase if email
+  end
 end

構造変更

uml diagram

コミット: fd92fd0

メッセージ

モデルの基礎知識 #3

変更されたファイル

  • M README.md

変更内容

commit fd92fd0b51adbd11e91b6021bfa29f52e6862fea
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 17:52:48 2017 +0900

    モデルの基礎知識 #3

diff --git a/README.md b/README.md
index 55fe13c..5e1ff05 100644
--- a/README.md
+++ b/README.md
@@ -338,6 +338,8 @@ git push heroku master
 + 主キー

 #### モデル
++ モデルの基礎知識
+
 #### セッション

 ### ユーザー認証

コミット: 0dabe2d

メッセージ

主キー #3

変更されたファイル

  • M README.md

変更内容

commit 0dabe2d4317c496dd69f48ff2c1d4a9a14008177
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 17:52:17 2017 +0900

    主キー #3

diff --git a/README.md b/README.md
index 0ee43f1..55fe13c 100644
--- a/README.md
+++ b/README.md
@@ -335,6 +335,7 @@ git push heroku master
 + 各種スケルトンの作成
 + マイグレーションスクリプト
 + マイグレーションの実行
++ 主キー

 #### モデル
 #### セッション

コミット: a232b59

メッセージ

マイグレーションの実行 #3

変更されたファイル

  • M README.md
  • M app/models/staff_member.rb
  • M config/database.yml
  • M db/schema.rb
  • A lib/tasks/auto_annotate_models.rake
  • M spec/factories/staff_members.rb
  • M spec/models/staff_member_spec.rb

変更内容

commit a232b591351e18862d4f6cff91d0b3581e610dd0
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 17:08:47 2017 +0900

    マイグレーションの実行 #3

diff --git a/README.md b/README.md
index 3696688..0ee43f1 100644
--- a/README.md
+++ b/README.md
@@ -334,6 +334,7 @@ git push heroku master
 #### マイグレーション
 + 各種スケルトンの作成
 + マイグレーションスクリプト
++ マイグレーションの実行

 #### モデル
 #### セッション
@@ -358,4 +359,6 @@ git push heroku master
 + [現場のプロが本気で教える HTML/CSSデザイン講義](https://www.amazon.co.jp/dp/B01K3SZGR0/ref=dp-kindle-redirect?_encoding=UTF8&btkr=1)
 + [現場のプロが本気で教える HTML/CSSデザイン講義 サンプルデータ](https://github.com/basara669/html_css_book)
 + [Bootstrap for Sass](https://github.com/twbs/bootstrap-sass)
-+ [Rails Bootstrap Forms](https://github.com/bootstrap-ruby/rails-bootstrap-forms)
\ No newline at end of file
++ [Rails Bootstrap Forms](https://github.com/bootstrap-ruby/rails-bootstrap-forms)
++ [Annotate (aka AnnotateModels)](https://github.com/ctran/annotate_models)
++ [MigrationComments](https://github.com/pinnymz/migration_comments)
\ No newline at end of file
diff --git a/app/models/staff_member.rb b/app/models/staff_member.rb
index 415eafe..409a66f 100644
--- a/app/models/staff_member.rb
+++ b/app/models/staff_member.rb
@@ -1,2 +1,26 @@
+# == Schema Information
+#
+# Table name: staff_members # 職員
+#
+#  id               :integer          not null, primary key
+#  email            :string(255)      not null               # メールアドレス
+#  email_for_index  :string(255)      not null               # 索引用メールアドレス
+#  family_name      :string(255)      not null               # 姓
+#  given_name       :string(255)      not null               # 名
+#  family_name_kana :string(255)      not null               # 姓(カナ)
+#  given_name_kana  :string(255)      not null               # 名(カナ)
+#  hashed_password  :string(255)                             # パスワード
+#  start_date       :date             not null               # 開始日
+#  end_date         :date                                    # 終了日
+#  suspended        :boolean          default("0"), not null # 停止フラグ
+#  created_at       :datetime         not null
+#  updated_at       :datetime         not null
+#
+# Indexes
+#
+#  index_staff_members_on_email_for_index                       (email_for_index) UNIQUE
+#  index_staff_members_on_family_name_kana_and_given_name_kana  (family_name_kana,given_name_kana)
+#
+
 class StaffMember < ApplicationRecord
 end
diff --git a/config/database.yml b/config/database.yml
index b097f5f..0c508ef 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -55,9 +55,6 @@ production:
   # For details on connection pooling, see rails configuration guide
   # http://guides.rubyonrails.org/configuring.html#database-pooling
   pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
-  database: baukis-kai_production
-  username: postgres
-  password: password
-  host: 127.0.0.1
+  url: postgres://postgres:password@127.0.0.1/baukis-kai_production
   port: 5432

diff --git a/db/schema.rb b/db/schema.rb
index 52ab025..8209b42 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,6 +10,23 @@
 #
 # It's strongly recommended that you check this file into your version control system.

-ActiveRecord::Schema.define(version: 0) do
+ActiveRecord::Schema.define(version: 20170118073759) do
+
+  create_table "staff_members", force: :cascade do |t|
+    t.string   "email",                            null: false
+    t.string   "email_for_index",                  null: false
+    t.string   "family_name",                      null: false
+    t.string   "given_name",                       null: false
+    t.string   "family_name_kana",                 null: false
+    t.string   "given_name_kana",                  null: false
+    t.string   "hashed_password"
+    t.date     "start_date",                       null: false
+    t.date     "end_date"
+    t.boolean  "suspended",        default: false, null: false
+    t.datetime "created_at",                       null: false
+    t.datetime "updated_at",                       null: false
+    t.index ["email_for_index"], name: "index_staff_members_on_email_for_index", unique: true
+    t.index ["family_name_kana", "given_name_kana"], name: "index_staff_members_on_family_name_kana_and_given_name_kana"
+  end

 end
diff --git a/lib/tasks/auto_annotate_models.rake b/lib/tasks/auto_annotate_models.rake
new file mode 100644
index 0000000..f85503d
--- /dev/null
+++ b/lib/tasks/auto_annotate_models.rake
@@ -0,0 +1,34 @@
+# NOTE: only doing this in development as some production environments (Heroku)
+# NOTE: are sensitive to local FS writes, and besides -- it's just not proper
+# NOTE: to have a dev-mode tool do its thing in production.
+if Rails.env.development?
+  task :set_annotation_options do
+    # You can override any of these by setting an environment variable of the
+    # same name.
+    Annotate.set_defaults({
+      'position_in_routes'   => "before",
+      'position_in_class'    => "before",
+      'position_in_test'     => "before",
+      'position_in_fixture'  => "before",
+      'position_in_factory'  => "before",
+      'show_indexes'         => "true",
+      'simple_indexes'       => "false",
+      'model_dir'            => "app/models",
+      'include_version'      => "false",
+      'require'              => "",
+      'exclude_tests'        => "false",
+      'exclude_fixtures'     => "false",
+      'exclude_factories'    => "false",
+      'ignore_model_sub_dir' => "false",
+      'skip_on_db_migrate'   => "false",
+      'format_bare'          => "true",
+      'format_rdoc'          => "false",
+      'format_markdown'      => "false",
+      'sort'                 => "false",
+      'force'                => "false",
+      'trace'                => "false",
+    })
+  end
+
+  Annotate.load_tasks
+end
diff --git a/spec/factories/staff_members.rb b/spec/factories/staff_members.rb
index 4abdb4a..19592b2 100644
--- a/spec/factories/staff_members.rb
+++ b/spec/factories/staff_members.rb
@@ -1,3 +1,27 @@
+# == Schema Information
+#
+# Table name: staff_members # 職員
+#
+#  id               :integer          not null, primary key
+#  email            :string(255)      not null               # メールアドレス
+#  email_for_index  :string(255)      not null               # 索引用メールアドレス
+#  family_name      :string(255)      not null               # 姓
+#  given_name       :string(255)      not null               # 名
+#  family_name_kana :string(255)      not null               # 姓(カナ)
+#  given_name_kana  :string(255)      not null               # 名(カナ)
+#  hashed_password  :string(255)                             # パスワード
+#  start_date       :date             not null               # 開始日
+#  end_date         :date                                    # 終了日
+#  suspended        :boolean          default("0"), not null # 停止フラグ
+#  created_at       :datetime         not null
+#  updated_at       :datetime         not null
+#
+# Indexes
+#
+#  index_staff_members_on_email_for_index                       (email_for_index) UNIQUE
+#  index_staff_members_on_family_name_kana_and_given_name_kana  (family_name_kana,given_name_kana)
+#
+
 FactoryGirl.define do
   factory :staff_member do

diff --git a/spec/models/staff_member_spec.rb b/spec/models/staff_member_spec.rb
index 290b09e..c26bb75 100644
--- a/spec/models/staff_member_spec.rb
+++ b/spec/models/staff_member_spec.rb
@@ -1,3 +1,27 @@
+# == Schema Information
+#
+# Table name: staff_members # 職員
+#
+#  id               :integer          not null, primary key
+#  email            :string(255)      not null               # メールアドレス
+#  email_for_index  :string(255)      not null               # 索引用メールアドレス
+#  family_name      :string(255)      not null               # 姓
+#  given_name       :string(255)      not null               # 名
+#  family_name_kana :string(255)      not null               # 姓(カナ)
+#  given_name_kana  :string(255)      not null               # 名(カナ)
+#  hashed_password  :string(255)                             # パスワード
+#  start_date       :date             not null               # 開始日
+#  end_date         :date                                    # 終了日
+#  suspended        :boolean          default("0"), not null # 停止フラグ
+#  created_at       :datetime         not null
+#  updated_at       :datetime         not null
+#
+# Indexes
+#
+#  index_staff_members_on_email_for_index                       (email_for_index) UNIQUE
+#  index_staff_members_on_family_name_kana_and_given_name_kana  (family_name_kana,given_name_kana)
+#
+
 require 'rails_helper'

 RSpec.describe StaffMember, type: :model do

構造変更

uml diagram

コミット: 09f91e4

メッセージ

マイグレーションスクリプト #3

変更されたファイル

  • M README.md
  • M db/migrate/20170118073759_create_staff_members.rb

変更内容

commit 09f91e435704ba9f57f994556cf6dc8233a8cd98
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 16:48:05 2017 +0900

    マイグレーションスクリプト #3

diff --git a/README.md b/README.md
index 0fe544d..3696688 100644
--- a/README.md
+++ b/README.md
@@ -333,6 +333,7 @@ git push heroku master
 ### ユーザー認証(1)
 #### マイグレーション
 + 各種スケルトンの作成
++ マイグレーションスクリプト

 #### モデル
 #### セッション
diff --git a/db/migrate/20170118073759_create_staff_members.rb b/db/migrate/20170118073759_create_staff_members.rb
index 26746d1..29f3bbc 100644
--- a/db/migrate/20170118073759_create_staff_members.rb
+++ b/db/migrate/20170118073759_create_staff_members.rb
@@ -1,8 +1,22 @@
 class CreateStaffMembers < ActiveRecord::Migration[5.0]
   def change
-    create_table :staff_members do |t|
+    create_table :staff_members, comment: '職員' do |t|
+      t.string :email, null: false, comment: 'メールアドレス'
+      t.string :email_for_index, null: false, comment: '索引用メールアドレス'
+      t.string :family_name, null: false, comment: '姓'
+      t.string :given_name, null: false, comment: '名'
+      t.string :family_name_kana, null: false, comment: '姓(カナ)'
+      t.string :given_name_kana, null: false, comment: '名(カナ)'
+      t.string :hashed_password, comment: 'パスワード'
+      t.date :start_date, null: false, comment: '開始日'
+      t.date :end_date, comment: '終了日'
+      t.boolean :suspended, null: false, default: false, comment: '停止フラグ'
+

       t.timestamps
     end
+
+    add_index :staff_members, :email_for_index, unique: true
+    add_index :staff_members, [ :family_name_kana, :given_name_kana ]
   end
 end

コミット: 9f0a984

メッセージ

各種スケルトンの作成 #3

変更されたファイル

  • M README.md
  • A app/models/staff_member.rb
  • A db/migrate/20170118073759_create_staff_members.rb
  • A spec/factories/staff_members.rb
  • A spec/models/staff_member_spec.rb

変更内容

commit 9f0a9847168e60ed65fbd11d14662a90632b382c
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 16:39:06 2017 +0900

    各種スケルトンの作成 #3

diff --git a/README.md b/README.md
index f24bf6f..0fe544d 100644
--- a/README.md
+++ b/README.md
@@ -332,6 +332,8 @@ git push heroku master

 ### ユーザー認証(1)
 #### マイグレーション
++ 各種スケルトンの作成
+
 #### モデル
 #### セッション

diff --git a/app/models/staff_member.rb b/app/models/staff_member.rb
new file mode 100644
index 0000000..415eafe
--- /dev/null
+++ b/app/models/staff_member.rb
@@ -0,0 +1,2 @@
+class StaffMember < ApplicationRecord
+end
diff --git a/db/migrate/20170118073759_create_staff_members.rb b/db/migrate/20170118073759_create_staff_members.rb
new file mode 100644
index 0000000..26746d1
--- /dev/null
+++ b/db/migrate/20170118073759_create_staff_members.rb
@@ -0,0 +1,8 @@
+class CreateStaffMembers < ActiveRecord::Migration[5.0]
+  def change
+    create_table :staff_members do |t|
+
+      t.timestamps
+    end
+  end
+end
diff --git a/spec/factories/staff_members.rb b/spec/factories/staff_members.rb
new file mode 100644
index 0000000..4abdb4a
--- /dev/null
+++ b/spec/factories/staff_members.rb
@@ -0,0 +1,5 @@
+FactoryGirl.define do
+  factory :staff_member do
+    
+  end
+end
diff --git a/spec/models/staff_member_spec.rb b/spec/models/staff_member_spec.rb
new file mode 100644
index 0000000..290b09e
--- /dev/null
+++ b/spec/models/staff_member_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe StaffMember, type: :model do
+  pending "add some examples to (or delete) #{__FILE__}"
+end

構造変更

uml diagram

コミット: 00c37bc

メッセージ

ユーザー認証(1) #3

変更されたファイル

  • M README.md

変更内容

commit 00c37bca856b8de006aca4940a37830a9733abe6
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 16:36:40 2017 +0900

    ユーザー認証(1) #3

diff --git a/README.md b/README.md
index a67d67c..f24bf6f 100644
--- a/README.md
+++ b/README.md
@@ -330,7 +330,11 @@ git push heroku master

 #### ActiveSupport::Concern

-### ユーザー認証
+### ユーザー認証(1)
+#### マイグレーション
+#### モデル
+#### セッション
+
 ### ユーザー認証
 ### ルーティング
 ### レコードの表示、新規作成、更新、削除

コミット: 7025e6b

メッセージ

エラーページ #2

変更されたファイル

  • M app/views/staff/top/index.html.erb

変更内容

commit 7025e6b724d0784ad10f0a980ad9716593a86211
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:45:10 2017 +0900

    エラーページ #2

diff --git a/app/views/staff/top/index.html.erb b/app/views/staff/top/index.html.erb
index ed1fd86..feba999 100644
--- a/app/views/staff/top/index.html.erb
+++ b/app/views/staff/top/index.html.erb
@@ -9,7 +9,11 @@
   </div>
   <ol class="NewsList">
     <li class="NewsList__item">
-      <time class="NewsList__head" datatime="2017-1-17">2016.10.12</time>
+      <time class="NewsList__head" datatime="2017-1-18">2017.1.18</time>
+      <span class="NewsList__body">エラーページを追加</span>
+    </li>
+    <li class="NewsList__item">
+      <time class="NewsList__head" datatime="2017-1-17">2017.1.17</time>
       <span class="NewsList__body">開発を開始しました</span>
     </li>
   </ol>

コミット: 768229d

メッセージ

ActiveSupport::Concern #2

変更されたファイル

  • M app/controllers/application_controller.rb
  • A app/controllers/concerns/error_handlers.rb
  • M config/environments/production.rb

変更内容

commit 768229df8ef676c58cbe95fba7f1e208a0f97e64
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:40:43 2017 +0900

    ActiveSupport::Concern #2

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index fb3280b..fb5507f 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -6,11 +6,7 @@ class ApplicationController < ActionController::Base
   class Forbidden < ActionController::ActionControllerError; end
   class IpAddressRejected < ActionController::ActionControllerError; end

-  rescue_from Exception, with: :rescue500
-  rescue_from Forbidden, with: :rescue403
-  rescue_from IpAddressRejected, with: :rescue403
-  rescue_from ActionController::RoutingError, with: :rescue404
-  rescue_from ActiveRecord::RecordNotFound, with: :rescue404
+  include ErrorHandlers if Rails.env.production?

   private
   def set_layout
@@ -21,18 +17,4 @@ class ApplicationController < ActionController::Base
     end
   end

-  def rescue404(e)
-    @exception = e
-    render 'errors/not_found', status: 404
-  end
-
-  def rescue403(e)
-    @exception = e
-    render 'errors/forbidden', status: 403
-  end
-
-  def rescue500(e)
-    @exception = e
-    render 'errors/internal_server_error', status: 500
-  end
 end
diff --git a/app/controllers/concerns/error_handlers.rb b/app/controllers/concerns/error_handlers.rb
new file mode 100644
index 0000000..b13f356
--- /dev/null
+++ b/app/controllers/concerns/error_handlers.rb
@@ -0,0 +1,28 @@
+module ErrorHandlers
+  extend ActiveSupport::Concern
+
+  included do
+    rescue_from Exception, with: :rescue500
+    rescue_from ApplicationController::Forbidden, with: :rescue403
+    rescue_from ApplicationController::IpAddressRejected, with: :rescue403
+    rescue_from ActionController::RoutingError, with: :rescue404
+    rescue_from ActiveRecord::RecordNotFound, with: :rescue404
+  end
+
+  private
+  def rescue404(e)
+    @exception = e
+    render 'errors/not_found', status: 404
+  end
+
+  def rescue403(e)
+    @exception = e
+    render 'errors/forbidden', status: 403
+  end
+
+  def rescue500(e)
+    @exception = e
+    render 'errors/internal_server_error', status: 500
+  end
+
+end
\ No newline at end of file
diff --git a/config/environments/production.rb b/config/environments/production.rb
index 3af0b22..a736dfc 100644
--- a/config/environments/production.rb
+++ b/config/environments/production.rb
@@ -2,7 +2,7 @@ Rails.application.configure do
   # Settings specified here will take precedence over those in config/application.rb.

   # Code is not reloaded between requests.
-  config.cache_classes = false
+  config.cache_classes = true

   # Eager load code on boot. This eager loads most of Rails and
   # your application in memory, allowing both threaded web servers

構造変更

uml diagram

コミット: 021bd97

メッセージ

例外ActiveRecord::RecordNotFoundの処理 #2

変更されたファイル

  • M README.md
  • M app/controllers/application_controller.rb

変更内容

commit 021bd973d108e4a426988940eb8a9090c1e3f2d0
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:32:46 2017 +0900

    例外ActiveRecord::RecordNotFoundの処理 #2

diff --git a/README.md b/README.md
index a7ad3fd..a67d67c 100644
--- a/README.md
+++ b/README.md
@@ -326,6 +326,7 @@ git push heroku master

 #### 404 Not Found
 + 例外ActionController::RoutingErrorの処理
++ 例外ActiveRecord::RecordNotFoundの処理

 #### ActiveSupport::Concern

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 5ed5818..fb3280b 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
   rescue_from Forbidden, with: :rescue403
   rescue_from IpAddressRejected, with: :rescue403
   rescue_from ActionController::RoutingError, with: :rescue404
+  rescue_from ActiveRecord::RecordNotFound, with: :rescue404

   private
   def set_layout

構造変更

uml diagram

コミット: cf24b78

メッセージ

例外ActionController::RoutingErrorの処理 #2

変更されたファイル

  • M README.md
  • M app/assets/stylesheets/components/common/_errors.scss
  • M app/controllers/admin/top_controller.rb
  • M app/controllers/application_controller.rb
  • M app/controllers/customer/top_controller.rb
  • A app/controllers/errors_controller.rb
  • A app/views/errors/not_found.html.erb
  • A app/views/errors/routing_error.html.erb
  • M config/routes.rb

変更内容

commit cf24b785c6a49ce82810aa8273c9933672a06b39
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:27:21 2017 +0900

    例外ActionController::RoutingErrorの処理 #2

diff --git a/README.md b/README.md
index 5d5c58a..a7ad3fd 100644
--- a/README.md
+++ b/README.md
@@ -325,6 +325,8 @@ git push heroku master
 + 動作の確認

 #### 404 Not Found
++ 例外ActionController::RoutingErrorの処理
+
 #### ActiveSupport::Concern

 ### ユーザー認証
diff --git a/app/assets/stylesheets/components/common/_errors.scss b/app/assets/stylesheets/components/common/_errors.scss
index 1f3979c..47e7ec3 100644
--- a/app/assets/stylesheets/components/common/_errors.scss
+++ b/app/assets/stylesheets/components/common/_errors.scss
@@ -16,5 +16,5 @@
     background-color: $very_light_gray;
     text-align: center;
   }
-  &__test--url { font-family: monospace; }
+  &__url { font-family: monospace; }
 }
\ No newline at end of file
diff --git a/app/controllers/admin/top_controller.rb b/app/controllers/admin/top_controller.rb
index 121ab66..d9a88b5 100644
--- a/app/controllers/admin/top_controller.rb
+++ b/app/controllers/admin/top_controller.rb
@@ -1,6 +1,5 @@
 class Admin::TopController < ApplicationController
   def index
-    raise IpAddressRejected
     render action: 'index'
   end
 end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 17ad04c..5ed5818 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base
   rescue_from Exception, with: :rescue500
   rescue_from Forbidden, with: :rescue403
   rescue_from IpAddressRejected, with: :rescue403
+  rescue_from ActionController::RoutingError, with: :rescue404

   private
   def set_layout
@@ -19,6 +20,11 @@ class ApplicationController < ActionController::Base
     end
   end

+  def rescue404(e)
+    @exception = e
+    render 'errors/not_found', status: 404
+  end
+
   def rescue403(e)
     @exception = e
     render 'errors/forbidden', status: 403
diff --git a/app/controllers/customer/top_controller.rb b/app/controllers/customer/top_controller.rb
index 592a8b3..9fc6012 100644
--- a/app/controllers/customer/top_controller.rb
+++ b/app/controllers/customer/top_controller.rb
@@ -1,6 +1,5 @@
 class Customer::TopController < ApplicationController
   def index
-    raise Forbidden
     render action: 'index'
   end
 end
diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb
new file mode 100644
index 0000000..a7396fc
--- /dev/null
+++ b/app/controllers/errors_controller.rb
@@ -0,0 +1,5 @@
+class ErrorsController < ApplicationController
+  def routing_error
+    raise ActionController::RoutingError,"No route matches #{request.path.inspect}"
+  end
+end
diff --git a/app/views/errors/not_found.html.erb b/app/views/errors/not_found.html.erb
new file mode 100644
index 0000000..98f882c
--- /dev/null
+++ b/app/views/errors/not_found.html.erb
@@ -0,0 +1,5 @@
+<div class="Error__box">
+  <h1>404 Not Found</h1>
+  <p>指定されたページは見つかりません。</p>
+  <p class="Error__url"><%= request.url %></p>
+</div>
\ No newline at end of file
diff --git a/app/views/errors/routing_error.html.erb b/app/views/errors/routing_error.html.erb
new file mode 100644
index 0000000..4dd3ea0
--- /dev/null
+++ b/app/views/errors/routing_error.html.erb
@@ -0,0 +1,2 @@
+<h1>Errors#routing_error</h1>
+<p>Find me in app/views/errors/routing_error.html.erb</p>
diff --git a/config/routes.rb b/config/routes.rb
index 504e1e9..e26d28b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,4 +1,6 @@
 Rails.application.routes.draw do
+  get 'errors/routing_error'
+
   namespace :staff do
     root 'top#index'
   end
@@ -13,4 +15,7 @@ Rails.application.routes.draw do
     get 'campaign/index'
     get 'campaign_submit', to: 'campaign#submit'
   end
+
+  root 'errors#routing_error'
+  get '*anything' => 'errors#routing_error'
 end

構造変更

uml diagram

コミット: 1b3255f

メッセージ

動作の確認 #2

変更されたファイル

  • M README.md
  • M app/controllers/admin/top_controller.rb
  • M app/controllers/customer/top_controller.rb

変更内容

commit 1b3255f6222f85167bc170e49e745227e91665cb
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:16:09 2017 +0900

    動作の確認 #2

diff --git a/README.md b/README.md
index 413988e..5d5c58a 100644
--- a/README.md
+++ b/README.md
@@ -322,6 +322,7 @@ git push heroku master
 #### 403 Forbidden
 + 例外の捕捉
 + ERBテンプレートの作成
++ 動作の確認

 #### 404 Not Found
 #### ActiveSupport::Concern
diff --git a/app/controllers/admin/top_controller.rb b/app/controllers/admin/top_controller.rb
index d9a88b5..121ab66 100644
--- a/app/controllers/admin/top_controller.rb
+++ b/app/controllers/admin/top_controller.rb
@@ -1,5 +1,6 @@
 class Admin::TopController < ApplicationController
   def index
+    raise IpAddressRejected
     render action: 'index'
   end
 end
diff --git a/app/controllers/customer/top_controller.rb b/app/controllers/customer/top_controller.rb
index 9fc6012..592a8b3 100644
--- a/app/controllers/customer/top_controller.rb
+++ b/app/controllers/customer/top_controller.rb
@@ -1,5 +1,6 @@
 class Customer::TopController < ApplicationController
   def index
+    raise Forbidden
     render action: 'index'
   end
 end

構造変更

uml diagram

コミット: f440eab

メッセージ

ERBテンプレートの作成 #2

変更されたファイル

  • M README.md
  • M app/controllers/application_controller.rb
  • A app/views/errors/forbidden.html.erb

変更内容

commit f440eabb52e0d4d5d35f1788eab76e8d9aa9705e
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:14:21 2017 +0900

    ERBテンプレートの作成 #2

diff --git a/README.md b/README.md
index 4ca0c75..413988e 100644
--- a/README.md
+++ b/README.md
@@ -320,6 +320,9 @@ git push heroku master
 + ビジュアルデザイン

 #### 403 Forbidden
++ 例外の捕捉
++ ERBテンプレートの作成
+
 #### 404 Not Found
 #### ActiveSupport::Concern

diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 3ab4c91..17ad04c 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -3,7 +3,12 @@ class ApplicationController < ActionController::Base

   layout :set_layout

+  class Forbidden < ActionController::ActionControllerError; end
+  class IpAddressRejected < ActionController::ActionControllerError; end
+
   rescue_from Exception, with: :rescue500
+  rescue_from Forbidden, with: :rescue403
+  rescue_from IpAddressRejected, with: :rescue403

   private
   def set_layout
@@ -14,6 +19,11 @@ class ApplicationController < ActionController::Base
     end
   end

+  def rescue403(e)
+    @exception = e
+    render 'errors/forbidden', status: 403
+  end
+
   def rescue500(e)
     @exception = e
     render 'errors/internal_server_error', status: 500
diff --git a/app/views/errors/forbidden.html.erb b/app/views/errors/forbidden.html.erb
new file mode 100644
index 0000000..2d58bdf
--- /dev/null
+++ b/app/views/errors/forbidden.html.erb
@@ -0,0 +1,13 @@
+<div class="Error__box">
+  <h1>403 Forbidden</h1>
+  <p>
+    <%=
+      case @exception
+      when ApplicationController::IpAddressRejected
+        "あなたのIPアドレス(#{request.ip})からは利用できません。"
+      else
+        '指定されたページを閲覧する権限がありません。'
+      end
+      %>
+  </p>
+</div>
\ No newline at end of file

構造変更

uml diagram

コミット: 7c47a5a

メッセージ

ビジュアルデザイン #2

変更されたファイル

  • M README.md
  • A app/assets/stylesheets/components/common/_errors.scss
  • M app/assets/stylesheets/main.scss
  • M app/controllers/admin/top_controller.rb
  • A app/views/errors/internal_server_error.html.erb

変更内容

commit 7c47a5a780720f8aa113ee6edf084a599e012c10
Author: k2works <kakimomokuri@gmail.com>
Date:   Wed Jan 18 13:00:55 2017 +0900

    ビジュアルデザイン #2

diff --git a/README.md b/README.md
index 6931138..4ca0c75 100644
--- a/README.md
+++ b/README.md
@@ -317,6 +317,7 @@ git push heroku master
 #### 500 Internal Server Error
 + 準備作業
 + 例外の捕捉
++ ビジュアルデザイン

 #### 403 Forbidden
 #### 404 Not Found
diff --git a/app/assets/stylesheets/components/common/_errors.scss b/app/assets/stylesheets/components/common/_errors.scss
new file mode 100644
index 0000000..1f3979c
--- /dev/null
+++ b/app/assets/stylesheets/components/common/_errors.scss
@@ -0,0 +1,20 @@
+@charset 'utf-8';
+
+// =====================
+// Error
+// ---------------------
+// エラー
+// =====================
+
+.Error {
+  &__box {
+    width: 600px;
+    margin: 20px auto;
+    padding: 20px;
+    border-radius: 10px;
+    border: solid 4px $dark_gray;
+    background-color: $very_light_gray;
+    text-align: center;
+  }
+  &__test--url { font-family: monospace; }
+}
\ No newline at end of file
diff --git a/app/assets/stylesheets/main.scss b/app/assets/stylesheets/main.scss
index 898bc2b..0d4f3b2 100644
--- a/app/assets/stylesheets/main.scss
+++ b/app/assets/stylesheets/main.scss
@@ -41,6 +41,9 @@
 // SNS
 @import "./components/common/sns";

+// エラー
+@import "./components/common/errors";
+
 // Others
 //----------------------------
 // ブログ抜粋
diff --git a/app/controllers/admin/top_controller.rb b/app/controllers/admin/top_controller.rb
index 532994c..d9a88b5 100644
--- a/app/controllers/admin/top_controller.rb
+++ b/app/controllers/admin/top_controller.rb
@@ -1,6 +1,5 @@
 class Admin::TopController < ApplicationController
   def index
-    raise
     render action: 'index'
   end
 end
diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb
new file mode 100644
index 0000000..07fa14d
--- /dev/null
+++ b/app/views/errors/internal_server_error.html.erb
@@ -0,0 +1,4 @@
+<div class="Error__box">
+  <h1>500 Internal Server Error</h1>
+  <p>申し訳ございません。システムエラーが発生しました。</p>
+</div>
\ No newline at end of file

構造変更

uml diagram