質問編集履歴

5

情報の追加

2020/10/03 04:24

投稿

manami0419
manami0419

スコア10

test CHANGED
File without changes
test CHANGED
@@ -64,6 +64,118 @@
64
64
 
65
65
 
66
66
 
67
+ こちらはroomコントローラーです。
68
+
69
+ @matchを定義しています。
70
+
71
+ ```
72
+
73
+ class RoomsController < ApplicationController
74
+
75
+  def index
76
+
77
+  @favorite_user_infos = current_user.favorite_user_infos #情報を取ってる
78
+
79
+  @favorite_users = current_user.user_info.favorite_users #ユーザーを取ってる
80
+
81
+  x = current_user.favorite_user_infos.pluck(:user_id)
82
+
83
+  y = current_user.user_info.favorite_users.ids
84
+
85
+  z = x & y
86
+
87
+  @match = User.where(id: z)
88
+
89
+ end
90
+
91
+ ```
92
+
93
+
94
+
95
+ この実装で使っているモデルは、Roomモデル、Userモデル、その二つの中間テーブルのRoomUserモデルです。
96
+
97
+ これはroomモデルです。
98
+
99
+ ```
100
+
101
+ class Room < ApplicationRecord
102
+
103
+  has_many :room_users
104
+
105
+  has_many :users, through: :room_users
106
+
107
+  has_many :messages
108
+
109
+
110
+
111
+  validates :name, presence: true
112
+
113
+ end
114
+
115
+ ```
116
+
117
+
118
+
119
+ これはUserモデルです。
120
+
121
+ ```
122
+
123
+ class User < ApplicationRecord
124
+
125
+  # Include default devise modules. Others available are:
126
+
127
+  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
128
+
129
+  devise :database_authenticatable, :registerable,
130
+
131
+  :recoverable, :rememberable, :validatable
132
+
133
+
134
+
135
+  has_one :user_info
136
+
137
+  has_many :favorites
138
+
139
+  has_many :favorite_user_infos, through: :favorites, source: :user_info
140
+
141
+  has_many :room_users
142
+
143
+  has_many :rooms, through: :room_users
144
+
145
+  has_many :messages
146
+
147
+
148
+
149
+  validates :nickname, presence: true
150
+
151
+  validates :gender, presence: true
152
+
153
+ end
154
+
155
+ ```
156
+
157
+
158
+
159
+ これはRoomUserモデルです。
160
+
161
+ ```
162
+
163
+
164
+
165
+ よろしくお願いします( ; ; )
166
+
167
+ class RoomUser < ApplicationRecord
168
+
169
+  belongs_to :room
170
+
171
+  belongs_to :user
172
+
173
+ end
174
+
175
+ ```
176
+
177
+
178
+
67
179
 
68
180
 
69
181
  ### 補足情報

4

補足情報の追加

2020/10/03 04:24

投稿

manami0419
manami0419

スコア10

test CHANGED
File without changes
test CHANGED
@@ -68,6 +68,10 @@
68
68
 
69
69
  ### 補足情報
70
70
 
71
+ selectボックスのオプションのdisabledを使うのかなと思いました。
72
+
73
+ ただ、「チャットルームに存在しているmatchは表示しない」という設定の仕方がわかりません。。
74
+
71
75
 
72
76
 
73
77
  必要な情報がありましたら、なんでもおっしゃってください。

3

情報の追加

2020/10/02 15:17

投稿

manami0419
manami0419

スコア10

test CHANGED
File without changes
test CHANGED
@@ -52,7 +52,15 @@
52
52
 
53
53
  ```
54
54
 
55
+ こちらは@matchに格納されているユーザー情報です。
55
56
 
57
+ ```
58
+
59
+ [#<User id: 4, nickname: "さちこ", gender: "女", email: "oo@oo.oo", created_at: "2020-09-26 05:00:23", updated_at: "2020-09-26 05:00:23">,
60
+
61
+ #<User id: 10, nickname: "さやか", gender: "女", email: "ss@ss.ss", created_at: "2020-09-27 05:09:51", updated_at: "2020-09-27 05:09:51">]
62
+
63
+ ```
56
64
 
57
65
 
58
66
 

2

文法の修正

2020/10/02 10:22

投稿

manami0419
manami0419

スコア10

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  マッチしたユーザーをセレクトボックスで選択して、チャットルームへ遷移するという仕様です。
6
6
 
7
- そこで一度セレクボックスで選択したユーザーは、今後チャットルーム作成画面でセレクトボックス内に表示されないようにしたいです。
7
+ そこでチャッルームに存在するユーザーは、今後チャットルーム作成画面でセレクトボックス内に表示されないようにしたいです。
8
8
 
9
9
  そうでないと同じユーザーのチャットルームが何個もできてしまうからです( ; ; )
10
10
 

1

文法の改善

2020/10/02 10:18

投稿

manami0419
manami0419

スコア10

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  こちらはマッチしたユーザーを表示しているセレクトボックスです。
18
18
 
19
- @matchがマッチしたユーザーのユーザー情報を表しています。
19
+ @matchがマッチした全てのユーザーのユーザー情報を表しています。
20
20
 
21
21
  ```html
22
22