-
Notifications
You must be signed in to change notification settings - Fork 0
masterブランチのコードレビューをお願いします。 #1
base: group-chat-test
Are you sure you want to change the base?
Changes from all commits
3af4384
0096a5f
56030d4
40fa193
a9728bc
934e0b1
48e3f0f
cd3dd40
14f7939
2b626b9
71ca895
48347d9
70f2b73
2cd3d97
64966ae
f29307b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| web: bundle exec puma -C config/puma.rb |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,24 @@ | ||
| # README | ||
| これは、LINEを模して製作された簡易チャットアプリです | ||
| LINEを模して製作された簡易チャットアプリです。 ProgateでRuby on Railsを学んだ直後に作られました。 | ||
|
|
||
| 製作者:Taishi Murakami | ||
| 製作時間:1週間 | ||
| 製作者:Taishi Murakami | ||
| 製作時間:1週間 | ||
|
|
||
| 主な機能: | ||
| メール認証によるユーザー登録機能 | ||
| ログイン/ログアウト機能 | ||
| 登録情報の変更機能 | ||
| 1対1でのチャット機能(メイン) | ||
| -使用言語・バージョン | ||
| -Ruby 2.5.1 | ||
| -Rails 5.2.0 | ||
|
|
||
| 参考にしたサイト: | ||
| 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でのチャット機能(メイン) | ||
|
|
||
| -備考 | ||
| -ローカル環境での一作目なのでかろうじて動くだけのダメアプリです。テストもリファクタリングもしていません。悪しからず。 | ||
|
|
||
| -参考にしたサイト: | ||
| -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) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| App.room = App.cable.subscriptions.create "RoomChannel", | ||
|
|
||
|
|
||
| connected: -> | ||
| # Called when the subscription is ready for use on the server | ||
|
|
||
|
|
@@ -10,10 +12,12 @@ 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} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. カンマと |
||
|
|
||
| $(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() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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: data['to_id']) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. =の前後はスペースをあけましょう There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 | ||
| end | ||
|
|
||
| def message_room_id(first_user, second_user) | ||
| first_id = first_user.id.to_i | ||
| second_id = second_user.id.to_i | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 19-20行で=位置を揃えると可読性が上がります。 |
||
| if first_id < second_id | ||
| "#{first_user.id}-#{second_user.id}" | ||
| else | ||
| "#{second_user.id}-#{first_user.id}" | ||
| end | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nits] |
||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 上の |
||
| @room_id = message_room_id(current_user, @user) | ||
| @messages = Message.where(room_id: @room_id) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @user後の=前後にはスペースをあけましょう There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. view側の実装を見ていないのでなんとも言えないですが、 あと、 |
||
| end | ||
|
|
||
| def message_room_id(first_user, second_user) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| 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 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ class ApplicationMailer < ActionMailer::Base | |
| default from: 'from@example.com' | ||
| layout 'mailer' | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. この行だけ、 |
||
| validates :room_id, presence: true | ||
| validates :content, presence: true, length: {maximum: 50} | ||
|
|
||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,9 @@ class User < ApplicationRecord | |
| :confirmable, :lockable, :timeoutable | ||
|
|
||
| has_many :messages,dependent: :destroy | ||
|
|
||
| # Validations | ||
| validates :email, presence: true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. たぶん |
||
| validates :username, presence: true | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. あと、ここもlengthくらいは入れた方がいいと思います! |
||
| validates :encrypted_password, presence: true | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,12 @@ | |
| <h1>Chat room</h1> | ||
|
|
||
| <form> | ||
| <label>Say something:</label><br> | ||
| <input type="hidden" name="to_id" value="<%= @user.id %>"> | ||
| <% if current_user.id==@user.id %> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 比較演算子前後にスペースを入れましょう |
||
| <label>It's your space. Write down whatever you like here! :</label><br> | ||
| <% else%> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. おしりの%前にスペースを入れましょう |
||
| <label>Send messages to <%= @user.username%>:</label><br> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. おしりの%前にスペースを入れましょう |
||
| <% end %> | ||
| <input type="text" data-behavior="room_speaker"> | ||
| </form> | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |
| <% @users.each do |user|%> | ||
| <div class="users-index-item"> | ||
| <div class="user-right"> | ||
| <p><%= link_to user.username,root_url%></p> | ||
| <p><%= link_to user.username,"/rooms/#{user.id}"%></p> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. カンマの後とおしりの%前にスペースを入れましょう |
||
| </div> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このようにAuthに関連するキーなどはgitにコミットしないようにしましょう |
||
| # ==> Controller configuration | ||
| # Configure the parent class to the devise controllers. | ||
| # config.parent_controller = 'DeviseController' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| Rails.application.routes.draw do | ||
|
|
||
| devise_for :user | ||
| get 'rooms/show'=> 'rooms#show' | ||
| get 'rooms/:id'=> 'rooms#show' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| get 'users/:id'=>'users#top' | ||
|
|
||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. カラム名の位置を揃えると可読性が上がります。 |
||
| end | ||
|
|
||
| create_table "users", force: :cascade do |t| | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= の後ろのスペースをあけるべきかと思います