質問編集履歴

5

jqueryを追加

2020/10/22 16:09

投稿

Zengo_Master
Zengo_Master

スコア19

test CHANGED
File without changes
test CHANGED
@@ -794,6 +794,8 @@
794
794
 
795
795
  "@rails/webpacker": "4.3.0",
796
796
 
797
+ "jquery": "^3.5.1",
798
+
797
799
  "turbolinks": "^5.2.0"
798
800
 
799
801
  },

4

package.jsonのコード追加

2020/10/22 16:09

投稿

Zengo_Master
Zengo_Master

スコア19

test CHANGED
File without changes
test CHANGED
@@ -774,6 +774,44 @@
774
774
 
775
775
 
776
776
 
777
+ package.json
778
+
779
+ ```
780
+
781
+ {
782
+
783
+ "name": "kifu_app",
784
+
785
+ "private": true,
786
+
787
+ "dependencies": {
788
+
789
+ "@rails/actioncable": "^6.0.0-alpha",
790
+
791
+ "@rails/activestorage": "^6.0.0-alpha",
792
+
793
+ "@rails/ujs": "^6.0.0-alpha",
794
+
795
+ "@rails/webpacker": "4.3.0",
796
+
797
+ "turbolinks": "^5.2.0"
798
+
799
+ },
800
+
801
+ "version": "0.1.0",
802
+
803
+ "devDependencies": {
804
+
805
+ "webpack-dev-server": "^3.11.0"
806
+
807
+ }
808
+
809
+ }
810
+
811
+ ```
812
+
813
+
814
+
777
815
  ## ブラウザでの表示
778
816
 
779
817
  ![イメージ説明](315544b58ade49fe219241f99b41bfc5.png)

3

コードの追加

2020/10/22 13:00

投稿

Zengo_Master
Zengo_Master

スコア19

test CHANGED
File without changes
test CHANGED
@@ -162,6 +162,8 @@
162
162
 
163
163
 
164
164
 
165
+ app/controllers/kifus_controller.rb
166
+
165
167
  ```ruby
166
168
 
167
169
  class KifusController < ApplicationController
@@ -366,6 +368,52 @@
366
368
 
367
369
 
368
370
 
371
+ app/assets/stylesheets/index.scss
372
+
373
+ ```scss
374
+
375
+ .index-wrapper {
376
+
377
+ margin: 20px;
378
+
379
+ }
380
+
381
+
382
+
383
+ .new-link {
384
+
385
+ font-size: 20px;
386
+
387
+ }
388
+
389
+
390
+
391
+ h2 {
392
+
393
+ margin-top: 10px;
394
+
395
+ }
396
+
397
+
398
+
399
+ .kifu-lists {
400
+
401
+ margin-top: 5px;
402
+
403
+ }
404
+
405
+
406
+
407
+ .one-kifu {
408
+
409
+ font-size: 18px;
410
+
411
+ }
412
+
413
+ ```
414
+
415
+
416
+
369
417
  app/views/kifus/new.html.erb
370
418
 
371
419
  ```html

2

全ファイルのコードを掲載

2020/10/20 06:26

投稿

Zengo_Master
Zengo_Master

スコア19

test CHANGED
File without changes
test CHANGED
@@ -146,6 +146,528 @@
146
146
 
147
147
 
148
148
 
149
+ config/routes.rb
150
+
151
+ ```ruby
152
+
153
+ Rails.application.routes.draw do
154
+
155
+ root to: 'kifus#index'
156
+
157
+ resources :kifus
158
+
159
+ end
160
+
161
+ ```
162
+
163
+
164
+
165
+ ```ruby
166
+
167
+ class KifusController < ApplicationController
168
+
169
+ before_action :set_kifu, only: [:edit, :show, :destroy, :update]
170
+
171
+
172
+
173
+ def index
174
+
175
+ @kifus = Kifu.all.order('date DESC')
176
+
177
+ end
178
+
179
+
180
+
181
+ def new
182
+
183
+ @kifu = Kifu.new
184
+
185
+ end
186
+
187
+
188
+
189
+ def create
190
+
191
+ @kifu = Kifu.create(kifu_params)
192
+
193
+ if @kifu.valid?
194
+
195
+ @kifu.save
196
+
197
+ redirect_to root_path
198
+
199
+ else
200
+
201
+ render 'new'
202
+
203
+ end
204
+
205
+ end
206
+
207
+
208
+
209
+ def edit
210
+
211
+ end
212
+
213
+
214
+
215
+ def update
216
+
217
+ if @kifu.update(kifu_params)
218
+
219
+ redirect_to kifu_path(@kifu.id)
220
+
221
+ else
222
+
223
+ render 'edit'
224
+
225
+ end
226
+
227
+ end
228
+
229
+
230
+
231
+ def show
232
+
233
+ end
234
+
235
+
236
+
237
+ def destroy
238
+
239
+ if @kifu.destroy
240
+
241
+ redirect_to root_path
242
+
243
+ else
244
+
245
+ redirect_to kifu_path(@kifu.id)
246
+
247
+ end
248
+
249
+ end
250
+
251
+
252
+
253
+ private
254
+
255
+
256
+
257
+ def kifu_params
258
+
259
+ params.require(:kifu).permit(:date, :opponent, :result_id, :type_id, :kifu)
260
+
261
+ end
262
+
263
+
264
+
265
+ def set_kifu
266
+
267
+ @kifu = Kifu.find(params[:id])
268
+
269
+ end
270
+
271
+
272
+
273
+ end
274
+
275
+ ```
276
+
277
+
278
+
279
+ app/views/kifus/index.html.erb
280
+
281
+ ```html
282
+
283
+ <div class="index-wrapper">
284
+
285
+
286
+
287
+ <div class="new-link">
288
+
289
+ <%= link_to '棋譜投稿ページへ', new_kifu_path %>
290
+
291
+ </div>
292
+
293
+
294
+
295
+ <h2><棋譜一覧></h2>
296
+
297
+
298
+
299
+ <div class="kifu-lists">
300
+
301
+ <% @kifus.each do |kifu| %>
302
+
303
+ <div class="one-kifu">
304
+
305
+
306
+
307
+ <%# 日付 %>
308
+
309
+ <span class="date">
310
+
311
+ <%= kifu.date %>
312
+
313
+ </span>
314
+
315
+
316
+
317
+ <%# 相手 %>
318
+
319
+ <span class="opponent">
320
+
321
+ <%= kifu.opponent %>
322
+
323
+ </span>
324
+
325
+
326
+
327
+ <%# 結果 %>
328
+
329
+ <span class="result">
330
+
331
+ <%= kifu.result.name %>
332
+
333
+ </span>
334
+
335
+
336
+
337
+ <%# 戦型 %>
338
+
339
+ <span class="type">
340
+
341
+ <%= kifu.type.name %>
342
+
343
+ </span>
344
+
345
+
346
+
347
+ <%# 棋譜リンク %>
348
+
349
+ <span class="kifu-page">
350
+
351
+ <%= link_to '棋譜', kifu_path(kifu.id) %>
352
+
353
+ </span>
354
+
355
+
356
+
357
+ </div>
358
+
359
+ <% end %>
360
+
361
+ </div>
362
+
363
+ </div>
364
+
365
+ ```
366
+
367
+
368
+
369
+ app/views/kifus/new.html.erb
370
+
371
+ ```html
372
+
373
+ <div class="new-wrapper">
374
+
375
+ <div class="input-forms">
376
+
377
+
378
+
379
+ <h2><対局情報入力></h2>
380
+
381
+
382
+
383
+ <%= form_with(model: @kifu, local: true) do |f| %>
384
+
385
+
386
+
387
+ <%# 日付 %>
388
+
389
+ <div class="input-field">
390
+
391
+ <%= f.label :date, '日付:' %>
392
+
393
+ <%= raw sprintf(
394
+
395
+ f.date_select(
396
+
397
+ :date,
398
+
399
+ use_month_numbers: true,
400
+
401
+ start_year: 2015,
402
+
403
+ end_year: 2025,
404
+
405
+ default: Date.today,
406
+
407
+ date_separator: '%s'),
408
+
409
+ '年 ', '月 ') + '日'
410
+
411
+ %>
412
+
413
+ </div>
414
+
415
+
416
+
417
+ <div class="input-field">
418
+
419
+ <%= f.label :opponent, '相手:' %>
420
+
421
+ <%= f.text_field :opponent %>
422
+
423
+ </div>
424
+
425
+
426
+
427
+ <div class="input-field">
428
+
429
+ <%= f.label :result_id, '結果:' %>
430
+
431
+ <%= f.collection_select :result_id, Result.all, :id, :name, {} %>
432
+
433
+ </div>
434
+
435
+
436
+
437
+ <div class="input-field">
438
+
439
+ <%= f.label :type_id, '戦型:' %>
440
+
441
+ <%= f.collection_select :type_id, Type.all, :id, :name, {} %>
442
+
443
+ </div>
444
+
445
+
446
+
447
+ <div class="input-field">
448
+
449
+ <%= f.label :kifu, '棋譜' %><br>
450
+
451
+ <%= f.text_area :kifu, placeholder: '棋譜を貼り付け', size: "35x5" %>
452
+
453
+ </div>
454
+
455
+
456
+
457
+ <div class="submit">
458
+
459
+ <%= f.submit "保存", class: 'submit-btn' %>
460
+
461
+ </div>
462
+
463
+
464
+
465
+ <div class="back">
466
+
467
+ <%= link_to "棋譜一覧へ戻る", root_path, class: "back-btn" %>
468
+
469
+ </div>
470
+
471
+ <% end %>
472
+
473
+ </div>
474
+
475
+ </div>
476
+
477
+ ```
478
+
479
+
480
+
481
+ app/assets/stylesheets/new.scss
482
+
483
+ ```scss
484
+
485
+ .new-wrapper {
486
+
487
+ margin: 20px;
488
+
489
+ }
490
+
491
+
492
+
493
+ .input-field {
494
+
495
+ margin-top: 20px;
496
+
497
+ }
498
+
499
+
500
+
501
+ .back {
502
+
503
+ font-size: 20px;
504
+
505
+ margin-top: 20px;
506
+
507
+ }
508
+
509
+
510
+
511
+ .submit-btn {
512
+
513
+ width: 50px;
514
+
515
+ height: 30px;
516
+
517
+ }
518
+
519
+ ```
520
+
521
+
522
+
523
+ app/views/kifus/show.html.erb
524
+
525
+ ```html
526
+
527
+ <div class="show-wrapper">
528
+
529
+
530
+
531
+ <div class="kifu-text">
532
+
533
+ <textarea id="fe_text" name="" rows="10" cols="40"><%= @kifu.kifu %></textarea>
534
+
535
+ <button class='my_clip_button' data-clipboard-target='fe_text' data-clipboard-text='Default clipboard text from attribute' id='d_clip_button'>
536
+
537
+ <b>コピー</b>
538
+
539
+ </button>
540
+
541
+ </div>
542
+
543
+
544
+
545
+ <strong>※解析は棋譜をコピーしてから押してね</strong>
546
+
547
+
548
+
549
+ <div class="btns">
550
+
551
+ <div class="edit">
552
+
553
+ <%= link_to "編集", edit_kifu_path(@kifu.id), method: :get, class: "edit-btn" %>
554
+
555
+ </div>
556
+
557
+
558
+
559
+ <div class="destroy">
560
+
561
+ <%= link_to "削除", kifu_path(@kifu.id), method: :delete, class: "destroy-btn" %>
562
+
563
+ </div>
564
+
565
+
566
+
567
+ <div class="analysis">
568
+
569
+ <%= link_to '解析', 'https://www.shogi-extend.com/adapter', class: "analysis-btn" %>
570
+
571
+ </div>
572
+
573
+ </div>
574
+
575
+
576
+
577
+ <div class="back">
578
+
579
+ <%= link_to '棋譜一覧へ戻る', root_path, class: "back-btn" %>
580
+
581
+ </div>
582
+
583
+
584
+
585
+ </div class="div">
586
+
587
+ ```
588
+
589
+
590
+
591
+ app/assets/stylesheets/show.scss
592
+
593
+ ```scss
594
+
595
+ .show-wrapper {
596
+
597
+ margin: 20px;
598
+
599
+ }
600
+
601
+
602
+
603
+
604
+
605
+ .btns {
606
+
607
+ display: flex;
608
+
609
+ align-items: center;
610
+
611
+ margin-top: 20px;
612
+
613
+ }
614
+
615
+
616
+
617
+ .edit, .destroy, .analysis, .copy {
618
+
619
+ margin-right: 20px;
620
+
621
+ }
622
+
623
+
624
+
625
+ .edit-btn, .destroy-btn, .analysis-btn {
626
+
627
+ font-size: 20px;
628
+
629
+ font-weight: bold;
630
+
631
+ text-decoration: none;
632
+
633
+ background-color: yellow;
634
+
635
+ padding: 5px;
636
+
637
+ border: 2px solid black;
638
+
639
+ border-radius: 5px;
640
+
641
+ }
642
+
643
+
644
+
645
+ .edit-btn {
646
+
647
+ color: black;
648
+
649
+ }
650
+
651
+
652
+
653
+ .destroy-btn {
654
+
655
+ color: red;
656
+
657
+ }
658
+
659
+
660
+
661
+ .analysis-btn {
662
+
663
+ color: blue;
664
+
665
+ }
666
+
667
+ ```
668
+
669
+
670
+
149
671
  app/javascript/packs/application.js
150
672
 
151
673
  ```js
@@ -204,74 +726,6 @@
204
726
 
205
727
 
206
728
 
207
- app/views/kifus/show.html.erb
208
-
209
- ```html
210
-
211
- <div class="show-wrapper">
212
-
213
-
214
-
215
- <div class="kifu-text">
216
-
217
- <textarea id="fe_text" name="" rows="10" cols="40"><%= @kifu.kifu %></textarea>
218
-
219
- <button class='my_clip_button' data-clipboard-target='fe_text' data-clipboard-text='Default clipboard text from attribute' id='d_clip_button'>
220
-
221
- <b>コピー</b>
222
-
223
- </button>
224
-
225
- </div>
226
-
227
-
228
-
229
- <strong>※解析は棋譜をコピーしてから押してね</strong>
230
-
231
-
232
-
233
- <div class="btns">
234
-
235
- <div class="edit">
236
-
237
- <%= link_to "編集", edit_kifu_path(@kifu.id), method: :get, class: "edit-btn" %>
238
-
239
- </div>
240
-
241
-
242
-
243
- <div class="destroy">
244
-
245
- <%= link_to "削除", kifu_path(@kifu.id), method: :delete, class: "destroy-btn" %>
246
-
247
- </div>
248
-
249
-
250
-
251
- <div class="analysis">
252
-
253
- <%= link_to '解析', 'https://www.shogi-extend.com/adapter', class: "analysis-btn" %>
254
-
255
- </div>
256
-
257
- </div>
258
-
259
-
260
-
261
- <div class="back">
262
-
263
- <%= link_to '棋譜一覧へ戻る', root_path, class: "back-btn" %>
264
-
265
- </div>
266
-
267
-
268
-
269
- </div class="div">
270
-
271
- ```
272
-
273
-
274
-
275
729
  ## ブラウザでの表示
276
730
 
277
731
  ![イメージ説明](315544b58ade49fe219241f99b41bfc5.png)

1

jQuery導入後のコード

2020/10/20 06:25

投稿

Zengo_Master
Zengo_Master

スコア19

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,134 @@
18
18
 
19
19
 
20
20
 
21
+ Gemfile
22
+
23
+ ```
24
+
25
+ source 'https://rubygems.org'
26
+
27
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
28
+
29
+
30
+
31
+ ruby '2.6.5'
32
+
33
+
34
+
35
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
36
+
37
+ gem 'rails', '~> 6.0.0'
38
+
39
+ # Use mysql as the database for Active Record
40
+
41
+ # gem 'mysql2', '>= 0.4.4'
42
+
43
+ gem 'mysql2', '0.5.3'
44
+
45
+ # Use Puma as the app server
46
+
47
+ gem 'puma', '~> 3.11'
48
+
49
+ # Use SCSS for stylesheets
50
+
51
+ gem 'sass-rails', '~> 5'
52
+
53
+ # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
54
+
55
+ gem 'webpacker', '~> 4.0'
56
+
57
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
58
+
59
+ gem 'turbolinks', '~> 5'
60
+
61
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
62
+
63
+ gem 'jbuilder', '~> 2.7'
64
+
65
+ # Use Redis adapter to run Action Cable in production
66
+
67
+ # gem 'redis', '~> 4.0'
68
+
69
+ # Use Active Model has_secure_password
70
+
71
+ # gem 'bcrypt', '~> 3.1.7'
72
+
73
+
74
+
75
+ # Use Active Storage variant
76
+
77
+ # gem 'image_processing', '~> 1.2'
78
+
79
+
80
+
81
+ # Reduces boot times through caching; required in config/boot.rb
82
+
83
+ gem 'bootsnap', '>= 1.4.2', require: false
84
+
85
+
86
+
87
+ group :development, :test do
88
+
89
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
90
+
91
+ gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
92
+
93
+ end
94
+
95
+
96
+
97
+ group :development do
98
+
99
+ # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
100
+
101
+ gem 'web-console', '>= 3.3.0'
102
+
103
+ gem 'listen', '>= 3.0.5', '< 3.2'
104
+
105
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
106
+
107
+ gem 'spring'
108
+
109
+ gem 'spring-watcher-listen', '~> 2.0.0'
110
+
111
+ gem 'rubocop', require: false
112
+
113
+ end
114
+
115
+
116
+
117
+ group :test do
118
+
119
+ # Adds support for Capybara system testing and selenium driver
120
+
121
+ gem 'capybara', '>= 2.15'
122
+
123
+ gem 'selenium-webdriver'
124
+
125
+ # Easy installation and use of web drivers to run system tests with browsers
126
+
127
+ gem 'webdrivers'
128
+
129
+ end
130
+
131
+
132
+
133
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
134
+
135
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
136
+
137
+
138
+
139
+ gem 'active_hash'
140
+
141
+ gem 'zeroclipboard-rails'
142
+
143
+ gem 'jquery-rails'
144
+
145
+ ```
146
+
147
+
148
+
21
149
  app/javascript/packs/application.js
22
150
 
23
151
  ```js
@@ -56,6 +184,14 @@
56
184
 
57
185
  //= require zeroclipboard
58
186
 
187
+ //= require jquery
188
+
189
+ //= require rails-ujs
190
+
191
+ //= require turbolinks
192
+
193
+ //= require_tree .
194
+
59
195
 
60
196
 
61
197
  $(document).ready(function() {