From 3af43849aac1ad7b9393228b73b74c6fec3c1d05 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Wed, 4 Jul 2018 04:25:41 +0900 Subject: [PATCH 01/15] connect to chat room and set @user --- app/controllers/rooms_controller.rb | 14 +++++++++++++- app/models/message.rb | 7 +++++++ app/views/rooms/show.html.erb | 2 +- app/views/users/top.html.erb | 2 +- config/routes.rb | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 5c4b2a9..b3ba933 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -2,6 +2,18 @@ class RoomsController < ApplicationController before_action :sign_in_required, only: [:show] def show - @messages = Message.all + @user=User.find_by(id: params[:id]) + @room_id = message_room_id(current_user, @user) + @messages = Message.where(room_id: @room_id) + end + + def message_room_id(first_user, second_user) + first_id = first_user.id.to_i + second_id = second_user.id.to_i + if first_id < second_id + "#{first_user.id}-#{second_user.id}" + else + "#{second_user.id}-#{first_user.id}" + end end end diff --git a/app/models/message.rb b/app/models/message.rb index 663196c..e31d133 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -1,4 +1,11 @@ class Message < ApplicationRecord after_create_commit { MessageBroadcastJob.perform_later self } belongs_to :user + + # Validations + validates :from_id, presence: true + validates :to_id, presence: true + validates :room_id, presence: true + validates :content, presence: true, length: {maximum: 50} + end diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb index e0c63be..e7dd86a 100644 --- a/app/views/rooms/show.html.erb +++ b/app/views/rooms/show.html.erb @@ -2,7 +2,7 @@

Chat room

-
+
diff --git a/app/views/users/top.html.erb b/app/views/users/top.html.erb index 1c18b79..eef3a12 100644 --- a/app/views/users/top.html.erb +++ b/app/views/users/top.html.erb @@ -6,7 +6,7 @@ <% @users.each do |user|%>
-

<%= link_to user.username,root_url%>

+

<%= link_to user.username,"/rooms/#{user.id}"%>

<% end %> diff --git a/config/routes.rb b/config/routes.rb index 206dde9..2a089bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,7 +1,7 @@ Rails.application.routes.draw do devise_for :user - get 'rooms/show'=> 'rooms#show' + get 'rooms/:id'=> 'rooms#show' get 'users/:id'=>'users#top' From 0096a5fde8b534976de9b296c0a23fdbef09fdfd Mon Sep 17 00:00:00 2001 From: TaishiM Date: Wed, 4 Jul 2018 11:12:46 +0900 Subject: [PATCH 02/15] Finish LINE-like-app --- app/assets/javascripts/channels/room.coffee | 1 + app/channels/room_channel.rb | 16 +++++++++++++++- app/views/rooms/show.html.erb | 1 + config/routes.rb | 2 ++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/channels/room.coffee b/app/assets/javascripts/channels/room.coffee index 843155f..7cfa318 100644 --- a/app/assets/javascripts/channels/room.coffee +++ b/app/assets/javascripts/channels/room.coffee @@ -14,6 +14,7 @@ App.room = App.cable.subscriptions.create "RoomChannel", $(document).on 'keypress', '[data-behavior~=room_speaker]', (event) -> if event.keyCode is 13 # return = send + # Roomチャンネルのspeakメソッドを実行 App.room.speak event.target.value event.target.value = '' event.preventDefault() diff --git a/app/channels/room_channel.rb b/app/channels/room_channel.rb index b70036f..7575acc 100644 --- a/app/channels/room_channel.rb +++ b/app/channels/room_channel.rb @@ -8,6 +8,20 @@ def unsubscribed end def speak(data) - Message.create! content: data['message'], user_id: current_user.id + user=User.find_by(id: 1) + room_id = message_room_id(current_user, user) + Message.create! content: data['message'], user_id: current_user.id, + from_id: current_user.id, to_id:user.id, + room_id:room_id + end + + def message_room_id(first_user, second_user) + first_id = first_user.id.to_i + second_id = second_user.id.to_i + if first_id < second_id + "#{first_user.id}-#{second_user.id}" + else + "#{second_user.id}-#{first_user.id}" + end end end diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb index e7dd86a..fd1a481 100644 --- a/app/views/rooms/show.html.erb +++ b/app/views/rooms/show.html.erb @@ -2,6 +2,7 @@

Chat room

+
diff --git a/config/routes.rb b/config/routes.rb index 2a089bd..80ad728 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,4 +6,6 @@ get 'users/:id'=>'users#top' root 'home#top' + + mount ActionCable.server => '/cable' end From 56030d4fc8ea57032089ba476ac97688821d72f7 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Thu, 5 Jul 2018 17:18:42 +0900 Subject: [PATCH 03/15] bichousei --- app/assets/javascripts/channels/room.coffee | 5 ++++- app/channels/room_channel.rb | 6 +++--- app/models/user.rb | 5 +++++ app/views/rooms/show.html.erb | 6 +++++- config/routes.rb | 2 -- db/migrate/20180630084154_add_column_to_messages.rb | 5 ----- db/schema.rb | 5 ++++- 7 files changed, 21 insertions(+), 13 deletions(-) delete mode 100644 db/migrate/20180630084154_add_column_to_messages.rb diff --git a/app/assets/javascripts/channels/room.coffee b/app/assets/javascripts/channels/room.coffee index 7cfa318..158006a 100644 --- a/app/assets/javascripts/channels/room.coffee +++ b/app/assets/javascripts/channels/room.coffee @@ -1,4 +1,6 @@ App.room = App.cable.subscriptions.create "RoomChannel", + + connected: -> # Called when the subscription is ready for use on the server @@ -10,7 +12,8 @@ App.room = App.cable.subscriptions.create "RoomChannel", # Called when there's incoming data on the websocket for this channel speak:(message) -> - @perform 'speak', message: message + to_id =$('input:hidden[name="to_id"]').val() + @perform 'speak', {message: message,to_id:to_id} $(document).on 'keypress', '[data-behavior~=room_speaker]', (event) -> if event.keyCode is 13 # return = send diff --git a/app/channels/room_channel.rb b/app/channels/room_channel.rb index 7575acc..9b0c355 100644 --- a/app/channels/room_channel.rb +++ b/app/channels/room_channel.rb @@ -8,11 +8,11 @@ def unsubscribed end def speak(data) - user=User.find_by(id: 1) + user=User.find_by(id: data['to_id']) room_id = message_room_id(current_user, user) Message.create! content: data['message'], user_id: current_user.id, - from_id: current_user.id, to_id:user.id, - room_id:room_id + from_id: current_user.id, to_id: user.id, + room_id: room_id end def message_room_id(first_user, second_user) diff --git a/app/models/user.rb b/app/models/user.rb index f500414..4a9cf74 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,4 +4,9 @@ class User < ApplicationRecord :confirmable, :lockable, :timeoutable has_many :messages,dependent: :destroy + + # Validations + validates :email, presence: true + validates :username, presence: true + validates :encrypted_password, presence: true end diff --git a/app/views/rooms/show.html.erb b/app/views/rooms/show.html.erb index fd1a481..56b7aeb 100644 --- a/app/views/rooms/show.html.erb +++ b/app/views/rooms/show.html.erb @@ -3,7 +3,11 @@
-
+ <% if current_user.id==@user.id %> +
+ <% else%> +
+ <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 80ad728..2a089bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,4 @@ get 'users/:id'=>'users#top' root 'home#top' - - mount ActionCable.server => '/cable' end diff --git a/db/migrate/20180630084154_add_column_to_messages.rb b/db/migrate/20180630084154_add_column_to_messages.rb deleted file mode 100644 index 1b491d3..0000000 --- a/db/migrate/20180630084154_add_column_to_messages.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddColumnToMessages < ActiveRecord::Migration[5.2] - def change - add_column :messages, :user_id, :integer - end -end diff --git a/db/schema.rb b/db/schema.rb index 9e12d2d..dd54dee 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,13 +10,16 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_06_30_084154) do +ActiveRecord::Schema.define(version: 2018_07_03_042018) do create_table "messages", force: :cascade do |t| t.text "content" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.integer "user_id" + t.integer "from_id" + t.integer "to_id" + t.string "room_id" end create_table "users", force: :cascade do |t| From 40fa193738f4af8be762adf9ecde3af4bffe5ec1 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Thu, 5 Jul 2018 17:45:48 +0900 Subject: [PATCH 04/15] set secret key --- config/initializers/devise.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index b3a7835..d67c9e7 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -8,8 +8,8 @@ # confirmation, reset password and unlock tokens in the database. # Devise will use the `secret_key_base` as its `secret_key` # by default. You can change it below and use your own secret key. - # config.secret_key = '36225be56b61efa00ddd192276401308319f57986469c4f528653eda4f44aed253fc887a07711360b0b3da4e641427cf3e02bd71350b62c10b83407f6acd7d1d' - + config.secret_key = '6ff05a2a5b47194687fe711bcec8a4dfed7f7350c2ab7842cb7cfe8ce0bf52b259b2b72f7635341c80f6437df9fe39b0e5f75a4bbce788bc249a5b6ce1de2f38' + # ==> Controller configuration # Configure the parent class to the devise controllers. # config.parent_controller = 'DeviseController' From a9728bc5d8262dd0884cf82131f40e5c12eac191 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Thu, 5 Jul 2018 19:31:29 +0900 Subject: [PATCH 05/15] modify README 2 --- README.md | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b106979..f35c9b0 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,14 @@ # README -これは、LINEを模して製作された簡易チャットアプリです - +これは、LINEを模して製作された簡易チャットアプリです 製作者:Taishi Murakami -製作時間:1週間 - -主な機能: - メール認証によるユーザー登録機能 - ログイン/ログアウト機能 - 登録情報の変更機能 - 1対1でのチャット機能(メイン) - -参考にしたサイト: - Deviseの導入:https://qiita.com/cigalecigales/items/f4274088f20832252374 - ActionCableの導入:https://qiita.com/jnchito/items/aec75fab42804287d71b - 1対1チャット機能の実装:https://qiita.com/YN6127yn/items/7ddd966141cca195b4da - DB設計:https://railsguides.jp/association_basics.html +製作時間:1週間 +*主な機能: + *メール認証によるユーザー登録機能 + *ログイン/ログアウト機能 + *登録情報の変更機能 + *1対1でのチャット機能(メイン) +*参考にしたサイト: + *Deviseの導入:[Qiita](https://qiita.com/cigalecigales/items/f4274088f20832252374) + *ActionCableの導入:[Qiita](https://qiita.com/jnchito/items/aec75fab42804287d71b) + *1対1チャット機能の実装:[Qiita](https://qiita.com/YN6127yn/items/7ddd966141cca195b4da) + *DB設計:[Rails Guide](https://railsguides.jp/association_basics.html) From 934e0b130b447776793b38218bd428553ec31f98 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Thu, 5 Jul 2018 19:32:41 +0900 Subject: [PATCH 06/15] modefy readme 3 --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index f35c9b0..8fc4aa4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,17 @@ # README これは、LINEを模して製作された簡易チャットアプリです -製作者:Taishi Murakami + +製作者:Taishi Murakami 製作時間:1週間 -*主な機能: - *メール認証によるユーザー登録機能 - *ログイン/ログアウト機能 - *登録情報の変更機能 + +*主な機能: + *メール認証によるユーザー登録機能 + *ログイン/ログアウト機能 + *登録情報の変更機能 *1対1でのチャット機能(メイン) -*参考にしたサイト: - *Deviseの導入:[Qiita](https://qiita.com/cigalecigales/items/f4274088f20832252374) - *ActionCableの導入:[Qiita](https://qiita.com/jnchito/items/aec75fab42804287d71b) - *1対1チャット機能の実装:[Qiita](https://qiita.com/YN6127yn/items/7ddd966141cca195b4da) + +*参考にしたサイト: + *Deviseの導入:[Qiita](https://qiita.com/cigalecigales/items/f4274088f20832252374) + *ActionCableの導入:[Qiita](https://qiita.com/jnchito/items/aec75fab42804287d71b) + *1対1チャット機能の実装:[Qiita](https://qiita.com/YN6127yn/items/7ddd966141cca195b4da) *DB設計:[Rails Guide](https://railsguides.jp/association_basics.html) From 48e3f0fe2d2241444ddd27c083c6141b9667ecdb Mon Sep 17 00:00:00 2001 From: TaishiM Date: Thu, 5 Jul 2018 19:38:09 +0900 Subject: [PATCH 07/15] modefy readme 4 --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 8fc4aa4..0164192 100644 --- a/README.md +++ b/README.md @@ -4,14 +4,14 @@ 製作者:Taishi Murakami 製作時間:1週間 -*主な機能: - *メール認証によるユーザー登録機能 - *ログイン/ログアウト機能 - *登録情報の変更機能 - *1対1でのチャット機能(メイン) +-主な機能: + -メール認証によるユーザー登録機能 + -ログイン/ログアウト機能 + -登録情報の変更機能 + -1対1でのチャット機能(メイン) -*参考にしたサイト: - *Deviseの導入:[Qiita](https://qiita.com/cigalecigales/items/f4274088f20832252374) - *ActionCableの導入:[Qiita](https://qiita.com/jnchito/items/aec75fab42804287d71b) - *1対1チャット機能の実装:[Qiita](https://qiita.com/YN6127yn/items/7ddd966141cca195b4da) - *DB設計:[Rails Guide](https://railsguides.jp/association_basics.html) +-参考にしたサイト: + -Deviseの導入:[deviseの使い方(rails5版)](https://qiita.com/cigalecigales/items/f4274088f20832252374) + -ActionCableの導入:[Rails 5 + ActionCableで作る!シンプルなチャットアプリ(DHH氏のデモ動画より)](https://qiita.com/jnchito/items/aec75fab42804287d71b) + -1対1チャット機能の実装:[Ruby on Rails チュートリアル 機能拡張5(メッセージ機能)](https://qiita.com/YN6127yn/items/7ddd966141cca195b4da) + -DB設計:[Rails Guide](https://railsguides.jp/association_basics.html) From cd3dd4009268a62280407f8404496b78a2c22fc4 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Fri, 6 Jul 2018 10:06:25 +0900 Subject: [PATCH 08/15] subtle change for deploy --- README.md | 4 ++++ app/assets/javascripts/application.js | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0164192..18a7415 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ 製作者:Taishi Murakami 製作時間:1週間 +-使用言語・バージョン + -Ruby 2.5.1 + -Rails 5.2.0 + -主な機能: -メール認証によるユーザー登録機能 -ログイン/ログアウト機能 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5537522..90148af 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,7 +12,6 @@ // //= require rails-ujs -//= require jquery/dist/jquery //= require activestorage //= require turbolinks //= require_tree . From 14f7939811d65df4997852a8524c6eeda5007dc2 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Fri, 6 Jul 2018 10:22:12 +0900 Subject: [PATCH 09/15] subtle change for deploy2 --- config/environments/production.rb | 2 +- config/puma.rb | 42 +++++++++---------------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/config/environments/production.rb b/config/environments/production.rb index b6b4e5e..08fbb31 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,7 +47,7 @@ config.action_cable.allowed_request_origins = [ /http:\/\/.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. diff --git a/config/puma.rb b/config/puma.rb index a5eccf8..1b19395 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,34 +1,16 @@ -# Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers: a minimum and maximum. -# Any libraries that use thread pools should be configured to match -# the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum; this matches the default thread size of Active Record. -# -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +workers Integer(ENV['WEB_CONCURRENCY'] || 2) +threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) threads threads_count, threads_count -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. -# -port ENV.fetch("PORT") { 3000 } +preload_app! -# Specifies the `environment` that Puma will run in. -# -environment ENV.fetch("RAILS_ENV") { "development" } +rackup DefaultRackup +port ENV['PORT'] || 3000 +environment ENV['RACK_ENV'] || 'development' -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). -# -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. -# -# preload_app! - -# Allow puma to be restarted by `rails restart` command. -plugin :tmp_restart +on_worker_boot do + # Worker specific setup for Rails 4.1+ + # See: https://devcenter.heroku.com/articles/ + # deploying-rails-applications-with-the-puma-web-server#on-worker-boot + ActiveRecord::Base.establish_connection +end From 2b626b91b1b11d4fb1a79e9df6dff85a430d96f0 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Mon, 9 Jul 2018 07:38:22 +0900 Subject: [PATCH 10/15] reset commit to modify-readme-4 --- Procfile | 1 + app/assets/stylesheets/custom.scss | 169 ++++++++++++++++++ .../20180703042018_add_column_to_messages.rb | 8 + 3 files changed, 178 insertions(+) create mode 100644 Procfile create mode 100644 app/assets/stylesheets/custom.scss create mode 100644 db/migrate/20180703042018_add_column_to_messages.rb diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..c2c566e --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +web: bundle exec puma -C config/puma.rb diff --git a/app/assets/stylesheets/custom.scss b/app/assets/stylesheets/custom.scss new file mode 100644 index 0000000..33e18d5 --- /dev/null +++ b/app/assets/stylesheets/custom.scss @@ -0,0 +1,169 @@ +/* reset ================================ */ +* { + box-sizing: border-box; + text-align: center; +} + +html { + font: 100%/1.5 'Avenir Next', 'Hiragino Sans', sans-serif; + line-height: 1.7; + letter-spacing: 1px; +} + +ul, li { + list-style-type: none; + padding: 0; + margin: 0; +} + +a { + text-decoration: none; + color: #2d3133; + font-size: 14px; + font-weight: bold; +} + +h1, h2, h3, h4, h5, h6, p { + margin: 0; +} + +input { + background-color: transparent; + outline-width: 0; +} + +form input[type="submit"] { + border: none; + cursor: pointer; +} + +/* 共通レイアウト ================================ */ +body { + color: #2d3133; + margin: 0; + min-height: 1vh; +} + +.main { + position: absolute; + top: 64px; + width: 100%; + height: auto; + min-height: 100%; + background-color: #f5f8fa; +} + +.container { + max-width: 600px; + margin: 30px auto; + padding-left: 15px; + padding-right: 15px; + clear: both; +} + +/* ヘッダー ================================ */ +header { + height: 64px; + z-index: 1; + width: 100%; + background-color: #5ae628; +} + +.header-logo { + float: left; + padding-left: 20px; + color: white; + font-size: 22px; + line-height: 64px; +} + +.header-logo a{ + color: white; + font-size: 40px; +} + +.header-menus { + float: right; + padding-right: 20px; +} + +.header-menus li { + float: left; + line-height: 64px; + font-size: 13px; + color: white; + padding-left: 15px; +} + +.header-menus a { + float: left; + font-size: 20px; + color: white; +} + +.header-menus .fa { + padding-right: 5px; +} + +.header-menus input[type="submit"] { + padding: 0 20px; + float: left; + line-height: 64px; + color: white; + margin: 0; + font-size: 13px; +} + +.notice,.alert{ + color:white; + background-color:orange; +} + +.top-page{ + margin-top:30px; +} + +.top-page h1,h2{ + padding:20px; +} + +.top-page p{ + padding:5px 10px; + background-color:#5ae628; + display:inline-block; +} + +.top-page a{ + color:white; +} + +.my-page{ + padding-top: 10px; +} + +.user-right { + width: 50%; + text-align: left; + display: table-cell; + vertical-align: middle; +} + +.user-right a{ + font-size: 30px; + font-weight: normal; +} + +.users-index-item { + font-size: 30px; + padding: 20px 30px; + background-color: white; + overflow: hidden; + box-shadow: 0 2px 6px #c1ced7; + display: table; + width: 100%; +} + +#messages{ + width: 100%; + border-top:1px solid gray; +} diff --git a/db/migrate/20180703042018_add_column_to_messages.rb b/db/migrate/20180703042018_add_column_to_messages.rb new file mode 100644 index 0000000..a091634 --- /dev/null +++ b/db/migrate/20180703042018_add_column_to_messages.rb @@ -0,0 +1,8 @@ +class AddColumnToMessages < ActiveRecord::Migration[5.2] + def change + add_column :messages, :user_id, :integer + add_column :messages, :from_id, :integer + add_column :messages, :to_id, :integer + add_column :messages, :room_id, :string + end +end From 71ca895df9d8f719314c8c898d1fe154d2c7c6e7 Mon Sep 17 00:00:00 2001 From: TaishiM Date: Mon, 9 Jul 2018 07:48:30 +0900 Subject: [PATCH 11/15] test --- README.md | 4 +++ app/assets/javascripts/application.js | 1 - config/environments/production.rb | 2 +- config/puma.rb | 42 ++++++++------------------- 4 files changed, 17 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 0164192..18a7415 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ 製作者:Taishi Murakami 製作時間:1週間 +-使用言語・バージョン + -Ruby 2.5.1 + -Rails 5.2.0 + -主な機能: -メール認証によるユーザー登録機能 -ログイン/ログアウト機能 diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5537522..90148af 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,7 +12,6 @@ // //= require rails-ujs -//= require jquery/dist/jquery //= require activestorage //= require turbolinks //= require_tree . diff --git a/config/environments/production.rb b/config/environments/production.rb index b6b4e5e..08fbb31 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -47,7 +47,7 @@ config.action_cable.allowed_request_origins = [ /http:\/\/.*/ ] # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. - # config.force_ssl = true + config.force_ssl = true # Use the lowest log level to ensure availability of diagnostic information # when problems arise. diff --git a/config/puma.rb b/config/puma.rb index a5eccf8..1b19395 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,34 +1,16 @@ -# Puma can serve each request in a thread from an internal thread pool. -# The `threads` method setting takes two numbers: a minimum and maximum. -# Any libraries that use thread pools should be configured to match -# the maximum value specified for Puma. Default is set to 5 threads for minimum -# and maximum; this matches the default thread size of Active Record. -# -threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +workers Integer(ENV['WEB_CONCURRENCY'] || 2) +threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) threads threads_count, threads_count -# Specifies the `port` that Puma will listen on to receive requests; default is 3000. -# -port ENV.fetch("PORT") { 3000 } +preload_app! -# Specifies the `environment` that Puma will run in. -# -environment ENV.fetch("RAILS_ENV") { "development" } +rackup DefaultRackup +port ENV['PORT'] || 3000 +environment ENV['RACK_ENV'] || 'development' -# Specifies the number of `workers` to boot in clustered mode. -# Workers are forked webserver processes. If using threads and workers together -# the concurrency of the application would be max `threads` * `workers`. -# Workers do not work on JRuby or Windows (both of which do not support -# processes). -# -# workers ENV.fetch("WEB_CONCURRENCY") { 2 } - -# Use the `preload_app!` method when specifying a `workers` number. -# This directive tells Puma to first boot the application and load code -# before forking the application. This takes advantage of Copy On Write -# process behavior so workers use less memory. -# -# preload_app! - -# Allow puma to be restarted by `rails restart` command. -plugin :tmp_restart +on_worker_boot do + # Worker specific setup for Rails 4.1+ + # See: https://devcenter.heroku.com/articles/ + # deploying-rails-applications-with-the-puma-web-server#on-worker-boot + ActiveRecord::Base.establish_connection +end From 70f2b731189a0293fe14d9de3aafa42c85632f9d Mon Sep 17 00:00:00 2001 From: TaishiM Date: Mon, 9 Jul 2018 08:25:53 +0900 Subject: [PATCH 12/15] ready for discussion --- app/assets/javascripts/application.js | 1 + config/puma.rb | 42 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 90148af..5537522 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -12,6 +12,7 @@ // //= require rails-ujs +//= require jquery/dist/jquery //= require activestorage //= require turbolinks //= require_tree . diff --git a/config/puma.rb b/config/puma.rb index 1b19395..a5eccf8 100644 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,16 +1,34 @@ -workers Integer(ENV['WEB_CONCURRENCY'] || 2) -threads_count = Integer(ENV['RAILS_MAX_THREADS'] || 5) +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } threads threads_count, threads_count -preload_app! +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } -rackup DefaultRackup -port ENV['PORT'] || 3000 -environment ENV['RACK_ENV'] || 'development' +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } -on_worker_boot do - # Worker specific setup for Rails 4.1+ - # See: https://devcenter.heroku.com/articles/ - # deploying-rails-applications-with-the-puma-web-server#on-worker-boot - ActiveRecord::Base.establish_connection -end +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart From 2cd3d974674eeccd94762b5dee2fb372192e529a Mon Sep 17 00:00:00 2001 From: TaishiM Date: Wed, 11 Jul 2018 18:47:35 +0900 Subject: [PATCH 13/15] set --- app/mailers/application_mailer.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b223..769f77a 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -2,3 +2,4 @@ class ApplicationMailer < ActionMailer::Base default from: 'from@example.com' layout 'mailer' end + From 64966ae55ce6bcc41df6b1b36f0dca378139092e Mon Sep 17 00:00:00 2001 From: Taishi-M-UTMafia <39128496+Taishi-M-UTMafia@users.noreply.github.com> Date: Sat, 25 Aug 2018 16:18:32 +0900 Subject: [PATCH 14/15] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 18a7415..f3dd35a 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # README -これは、LINEを模して製作された簡易チャットアプリです +LINEを模して製作された簡易チャットアプリです。 ProgateでRuby on Railsを学んだ直後に作られました。 製作者:Taishi Murakami 製作時間:1週間 From f29307b16bc574919174497c83225b4d7dfdfdf2 Mon Sep 17 00:00:00 2001 From: Taishi-M-UTMafia <39128496+Taishi-M-UTMafia@users.noreply.github.com> Date: Sat, 25 Aug 2018 16:20:21 +0900 Subject: [PATCH 15/15] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f3dd35a..1259433 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,9 @@ LINEを模して製作された簡易チャットアプリです。 ProgateでRu -ログイン/ログアウト機能 -登録情報の変更機能 -1対1でのチャット機能(メイン) + +-備考 + -ローカル環境での一作目なのでかろうじて動くだけのダメアプリです。テストもリファクタリングもしていません。悪しからず。 -参考にしたサイト: -Deviseの導入:[deviseの使い方(rails5版)](https://qiita.com/cigalecigales/items/f4274088f20832252374)