質問編集履歴
4
誤ったコードを記載し、申し訳ありませんでした。訂正いたしましたので、ご確認頂けますと幸いです。何卒宜しく御願い致します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -175,7 +175,8 @@
|
|
175
175
|
|
176
176
|
```
|
177
177
|
|
178
|
+
###変更:グループで作成したタスクの表示画面のビュー
|
178
|
-
|
179
|
+
変更前:タスクの新規作成画面のビュー(個人とグループ)
|
179
180
|
|
180
181
|
```app/views/task/index.html.erb
|
181
182
|
<header class="header2">
|
@@ -293,7 +294,7 @@
|
|
293
294
|
[個人でのタスク作成の現状](https://gyazo.com/1008f7b5b84a7cc49d5b672bed3f1d01)
|
294
295
|
|
295
296
|
- ozroro 様にご教授頂いた通り、上記task.controller.rb内に対して、Group.find_by(id: params[:group_id])へ変更し、新規作成画面を表示することができました!
|
296
|
-
- しかし、
|
297
|
+
- しかし、下記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
|
297
298
|
の条件分岐では、elseの方にいかず、groupの方を読み込んでしまいます。
|
298
299
|
- 動画上では、メリーと表示されているheaderはありますが、目標はそのheaderは表示されないこと。
|
299
300
|
|
@@ -302,4 +303,50 @@
|
|
302
303
|
|
303
304
|
- グループではタスクの新規作成、表示はできる。しかし、バイキンマンと表示されているheaderが、タスク新規作成画面になるとメリーになってしまう。(おそらく、DBのgroupテーブルのidの1を読み込んでいる。
|
304
305
|
|
305
|
-
仮説も含めてみました。お手数ですが、何卒ご教授の程宜しく御願い致します。
|
306
|
+
仮説も含めてみました。お手数ですが、何卒ご教授の程宜しく御願い致します。
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
#追記3
|
312
|
+
##追記1の上記の「タスクの新規作成画面のビュー(個人とグループ)」は「グループで作成したタスクの表示画面のビュー」でした。申し訳ありませんでした。
|
313
|
+
###「タスクの新規作成画面のビュー(個人とグループ)」
|
314
|
+
- ifとelseで条件分岐しております。
|
315
|
+
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
```
|
320
|
+
<% - if @group_id.present?%>
|
321
|
+
<header class="header2">
|
322
|
+
<nav class="nav2">
|
323
|
+
<ul class="header_menu2">
|
324
|
+
<li class="nav-link">
|
325
|
+
<%= @group.name %>
|
326
|
+
</li>
|
327
|
+
<ul class="header_menu2_inner2">
|
328
|
+
<li><%= link_to "Create Group Tasks", new_group_task_path(@group), class: "nav-link listNew2", method: :get %></li>
|
329
|
+
<li><%= link_to "Edit Group",edit_group_path(@group), class: "nav-link listNew3", method: :get %></li>
|
330
|
+
</ul>
|
331
|
+
</ul>
|
332
|
+
</nav>
|
333
|
+
</header>
|
334
|
+
<div class="tasknewPage">
|
335
|
+
<div class="container">
|
336
|
+
<%= form_with model: @task, url: { action: :create }, class: "new_task", local: true do |f| %>
|
337
|
+
<%= f.label :title %>
|
338
|
+
<%= f.text_field :title, autofocus: true, class: "form-control taskName", placeholder: "タスク名" %>
|
339
|
+
<div class="text-center"><%= f.submit "作成", class: "submitBtn" %></div>
|
340
|
+
<% end %>
|
341
|
+
|
342
|
+
<% else %>
|
343
|
+
<%= form_with model: @task, url: { action: :create }, class: "new_task", local: true do |f| %>
|
344
|
+
<%= f.label :title %>
|
345
|
+
<%= f.text_field :title, autofocus: true, class: "form-control taskName", placeholder: "タスク名" %>
|
346
|
+
<div class="text-center"><%= f.submit "作成", class: "submitBtn" %></div>
|
347
|
+
<% end %>
|
348
|
+
<% end %>
|
349
|
+
|
350
|
+
|
351
|
+
|
352
|
+
```
|
3
少し文言追加いたしました。何卒宜しく御願い致します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -292,7 +292,7 @@
|
|
292
292
|
####個人でタスク作成の場合
|
293
293
|
[個人でのタスク作成の現状](https://gyazo.com/1008f7b5b84a7cc49d5b672bed3f1d01)
|
294
294
|
|
295
|
-
- ご教授頂いた通り、上記task.controller.rb内
|
295
|
+
- ozroro 様にご教授頂いた通り、上記task.controller.rb内に対して、Group.find_by(id: params[:group_id])へ変更し、新規作成画面を表示することができました!
|
296
296
|
- しかし、上記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
|
297
297
|
の条件分岐では、elseの方にいかず、groupの方を読み込んでしまいます。
|
298
298
|
- 動画上では、メリーと表示されているheaderはありますが、目標はそのheaderは表示されないこと。
|
2
ご教授いただきありがとうございます。情報を追加いたしました。何卒宜しく御願い致します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -281,4 +281,25 @@
|
|
281
281
|
add_foreign_key "tasks", "groups"
|
282
282
|
add_foreign_key "tasks", "users"
|
283
283
|
end
|
284
|
-
```
|
284
|
+
```
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
#追記2
|
290
|
+
|
291
|
+
###タスク作成画面の表示画面
|
292
|
+
####個人でタスク作成の場合
|
293
|
+
[個人でのタスク作成の現状](https://gyazo.com/1008f7b5b84a7cc49d5b672bed3f1d01)
|
294
|
+
|
295
|
+
- ご教授頂いた通り、上記task.controller.rb内の記述を変更し、新規作成画面を表示することができました!
|
296
|
+
- しかし、上記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
|
297
|
+
の条件分岐では、elseの方にいかず、groupの方を読み込んでしまいます。
|
298
|
+
- 動画上では、メリーと表示されているheaderはありますが、目標はそのheaderは表示されないこと。
|
299
|
+
|
300
|
+
###グループでタスク作成の画面
|
301
|
+
[グループでのタスク作成の現状](https://gyazo.com/7e4eb04ba36dd435fe77446875423613)
|
302
|
+
|
303
|
+
- グループではタスクの新規作成、表示はできる。しかし、バイキンマンと表示されているheaderが、タスク新規作成画面になるとメリーになってしまう。(おそらく、DBのgroupテーブルのidの1を読み込んでいる。
|
304
|
+
|
305
|
+
仮説も含めてみました。お手数ですが、何卒ご教授の程宜しく御願い致します。
|
1
ご確認ありがとうございます。追記いたしました。宜しく御願い致します。
title
CHANGED
File without changes
|
body
CHANGED
@@ -101,4 +101,184 @@
|
|
101
101
|
必要な情報等ございましたら、ご教授頂けますと幸いです。
|
102
102
|
|
103
103
|
|
104
|
-
以上、お手数ですが、何卒ご教授の程宜しく御願い致します。
|
104
|
+
以上、お手数ですが、何卒ご教授の程宜しく御願い致します。
|
105
|
+
|
106
|
+
|
107
|
+
#追記
|
108
|
+
|
109
|
+
####groupsモデルのコード
|
110
|
+
|
111
|
+
```groub.rb
|
112
|
+
class Group < ApplicationRecord
|
113
|
+
has_many :group_users, dependent: :destroy
|
114
|
+
has_many :users, through: :group_users, dependent: :destroy
|
115
|
+
has_many :tasks, dependent: :destroy
|
116
|
+
|
117
|
+
validates :name, presence: true, uniqueness: true
|
118
|
+
end
|
119
|
+
```
|
120
|
+
|
121
|
+
###Taskモデルのコード
|
122
|
+
|
123
|
+
```task.rb
|
124
|
+
class Task < ApplicationRecord
|
125
|
+
# belongs_to :group
|
126
|
+
belongs_to :user
|
127
|
+
# belongs_to :groups
|
128
|
+
has_many :comments, dependent: :destroy
|
129
|
+
|
130
|
+
# validates :title, length: {in: 1..255}
|
131
|
+
end
|
132
|
+
```
|
133
|
+
|
134
|
+
###個人モデルのコード
|
135
|
+
|
136
|
+
```user.rb
|
137
|
+
class User < ApplicationRecord
|
138
|
+
# Include default devise modules. Others available are:
|
139
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
140
|
+
#usernameを必須・一意とする
|
141
|
+
|
142
|
+
devise :database_authenticatable, :registerable,
|
143
|
+
:recoverable, :rememberable, :validatable
|
144
|
+
|
145
|
+
has_many :group_users, dependent: :destroy
|
146
|
+
has_many :groups, through: :group_users, dependent: :destroy
|
147
|
+
has_many :tasks, dependent: :destroy
|
148
|
+
|
149
|
+
validates :username, presence: true, length: { maximum: 20 }
|
150
|
+
#usernameを利用してログインするようにオーバーライド
|
151
|
+
def self.find_first_by_auth_conditions(warden_conditions)
|
152
|
+
conditions = warden_conditions.dup
|
153
|
+
if login = conditions.delete(:login)
|
154
|
+
#認証の条件式を変更する
|
155
|
+
where(conditions).where(["username = :value", { :value => username }]).first
|
156
|
+
else
|
157
|
+
where(conditions).first
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
#emailを不要とする
|
162
|
+
def email_required?
|
163
|
+
false
|
164
|
+
end
|
165
|
+
|
166
|
+
def email_changed?
|
167
|
+
false
|
168
|
+
end
|
169
|
+
|
170
|
+
def will_save_change_to_email?
|
171
|
+
false
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
```
|
177
|
+
|
178
|
+
###タスクの新規作成画面のビュー(個人とグループ)
|
179
|
+
|
180
|
+
```app/views/task/index.html.erb
|
181
|
+
<header class="header2">
|
182
|
+
<nav class="nav2">
|
183
|
+
<ul class="header_menu2">
|
184
|
+
<li class="nav-link">
|
185
|
+
<%= @group.name %>
|
186
|
+
</li>
|
187
|
+
<ul class="header_menu2_inner2">
|
188
|
+
<li><%= link_to "Create Group Tasks", new_group_task_path(@group), class: "nav-link listNew2" %></li>
|
189
|
+
<li><%= link_to "Edit Group",edit_group_path(@group), class: "nav-link listNew3", method: :get %></li>
|
190
|
+
</ul>
|
191
|
+
</ul>
|
192
|
+
</nav>
|
193
|
+
</header>
|
194
|
+
|
195
|
+
<div class="topPage">
|
196
|
+
<div class="taskWrapper">
|
197
|
+
<% @group.tasks.each do |task| %>
|
198
|
+
<div class="task">
|
199
|
+
<div class="task_header">
|
200
|
+
<h2 class="task_header_title"><%= task.title %></h2>
|
201
|
+
<div class="task_header_action">
|
202
|
+
<%= link_to content_tag(:i, '', class: 'fas fa-trash'), task, method: :delete, data: { confirm: "#{task.title}を本当に削除しますか?" } %>
|
203
|
+
<%= link_to(content_tag(:i, '', class: 'fas fa-pen'), edit_task_path(task)) %>
|
204
|
+
</div>
|
205
|
+
</div>
|
206
|
+
<div class="commentWrapper">
|
207
|
+
<% task.comments.each do |comment| %>
|
208
|
+
<%= link_to task_comment_path(task, comment), class:"commentDetail_link" do %>
|
209
|
+
<div class="comment">
|
210
|
+
<h3 class="comment_title"><%= comment.title %></h3>
|
211
|
+
<% if comment.memo.size > 0 %>
|
212
|
+
<div class="comment_detail is-exist"><i class="fas fa-bars"></i></div>
|
213
|
+
<% end %>
|
214
|
+
</div>
|
215
|
+
<% end %>
|
216
|
+
<% end %>
|
217
|
+
<div class="addComment">
|
218
|
+
<i class="far fa-plus-square"></i>
|
219
|
+
<%= link_to "さらにコメントを追加", new_task_comment_path(task), class: "addComment_link" %>
|
220
|
+
</div>
|
221
|
+
</div>
|
222
|
+
</div>
|
223
|
+
<% end %>
|
224
|
+
</div>
|
225
|
+
</div>
|
226
|
+
```
|
227
|
+
|
228
|
+
###groups, tasks, 個人テーブルの定義
|
229
|
+
|
230
|
+
```schema.rb
|
231
|
+
ActiveRecord::Schema.define(version: 2020_02_25_061850) do
|
232
|
+
|
233
|
+
create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
234
|
+
t.string "title", null: false
|
235
|
+
t.text "memo"
|
236
|
+
t.bigint "task_id", null: false
|
237
|
+
t.datetime "created_at", null: false
|
238
|
+
t.datetime "updated_at", null: false
|
239
|
+
t.index ["task_id"], name: "index_comments_on_task_id"
|
240
|
+
end
|
241
|
+
|
242
|
+
create_table "group_users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
243
|
+
t.bigint "group_id"
|
244
|
+
t.bigint "user_id"
|
245
|
+
t.datetime "created_at", null: false
|
246
|
+
t.datetime "updated_at", null: false
|
247
|
+
t.index ["group_id"], name: "index_group_users_on_group_id"
|
248
|
+
t.index ["user_id"], name: "index_group_users_on_user_id"
|
249
|
+
end
|
250
|
+
|
251
|
+
create_table "groups", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
252
|
+
t.string "name", null: false
|
253
|
+
t.datetime "created_at", null: false
|
254
|
+
t.datetime "updated_at", null: false
|
255
|
+
t.index ["name"], name: "index_groups_on_name", unique: true
|
256
|
+
end
|
257
|
+
|
258
|
+
create_table "tasks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
259
|
+
t.string "title", null: false
|
260
|
+
t.bigint "user_id", null: false
|
261
|
+
t.bigint "group_id"
|
262
|
+
t.datetime "created_at", null: false
|
263
|
+
t.datetime "updated_at", null: false
|
264
|
+
t.index ["group_id"], name: "index_tasks_on_group_id"
|
265
|
+
t.index ["user_id"], name: "index_tasks_on_user_id"
|
266
|
+
end
|
267
|
+
|
268
|
+
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
269
|
+
t.string "encrypted_password", default: "", null: false
|
270
|
+
t.string "reset_password_token"
|
271
|
+
t.datetime "reset_password_sent_at"
|
272
|
+
t.datetime "remember_created_at"
|
273
|
+
t.datetime "created_at", null: false
|
274
|
+
t.datetime "updated_at", null: false
|
275
|
+
t.string "username", default: "", null: false
|
276
|
+
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
|
277
|
+
end
|
278
|
+
|
279
|
+
add_foreign_key "group_users", "groups"
|
280
|
+
add_foreign_key "group_users", "users"
|
281
|
+
add_foreign_key "tasks", "groups"
|
282
|
+
add_foreign_key "tasks", "users"
|
283
|
+
end
|
284
|
+
```
|