質問編集履歴

1

コードが見づらい状態だったので、コードの挿入内に入るよう、見やすいように修正しました。

2021/12/25 22:39

投稿

umakichi
umakichi

スコア44

test CHANGED
File without changes
test CHANGED
@@ -4,121 +4,269 @@
4
4
 
5
5
 
6
6
 
7
+ view/index.html.erb
8
+
9
+
10
+
7
11
  ```ここに言語を入力 view/index.html.erb
8
12
 
13
+
14
+
15
+ <h3>犬情報一覧</h3>
16
+
17
+
18
+
19
+ <table>
20
+
21
+ <thead>
22
+
23
+ <tr>
24
+
25
+  <th>写真</th>
26
+
27
+ <th>id</th>
28
+
29
+ <th>名前</th>
30
+
31
+ <th>犬種</th>
32
+
33
+ <th>年齢</th>
34
+
35
+ <th>一言紹介</th>
36
+
37
+ <th>性格</th>
38
+
39
+ <th>住所</th>
40
+
41
+ </tr>
42
+
43
+ </thead>
44
+
45
+
46
+
47
+ <tbody>
48
+
49
+ <% @dogs.each do |dog| %>
50
+
51
+ <tr>
52
+
53
+ <td> <%= image_tag @dogs.image ,class:'dog-image'%></td>
54
+
55
+ <td>No.<%= dog.id %></td>
56
+
57
+ <td><%= dog.name %>ちゃん</td>
58
+
59
+ <td><%= dog.kind %></td>
60
+
61
+ <td><%= dog.old %>歳</td>
62
+
63
+ <td><%= dog.dog_pr %></td>
64
+
65
+ <td><%= dog.personality %></td>
66
+
67
+ <td><%= dog.address %></td>
68
+
69
+ </tr>
70
+
71
+ <% end %>
72
+
73
+ </tbody>
74
+
75
+ </table>
76
+
77
+
78
+
79
+ <p><%= link_to "ワンちゃん新規登録", :new_dog %></p>
80
+
81
+
82
+
83
+ ```show.html.erb
84
+
85
+ ```ここに言語を入力
86
+
87
+ <p id="notice"><%= notice %></p>
88
+
89
+
90
+
91
+ <div class="dog-show-wrap">
92
+
93
+ <div class="dog-show-image">
94
+
95
+ <%= image_tag @dog.image ,class:'dog-show-image'%>
96
+
97
+ </div>
98
+
99
+ <div class="dog-show-text">
100
+
101
+ <p class="showText"><%= @dog.name %>ちゃん</p>
102
+
103
+ <p class="showText"><%= @dog.old %></p>
104
+
105
+ <p class="showText"><%= @dog.kind %></p>
106
+
107
+ <p class="showText"><%= @dog.dog_pr %></p>
108
+
109
+ <p class="showText"><%= @dog.personality %></p>
110
+
111
+ <p class="showText"><%= @dog.address %></p>
112
+
113
+ </div>
114
+
115
+ </div>
116
+
117
+
118
+
119
+ <%= link_to 'Edit', edit_dog_path(@dog) %> |
120
+
121
+ <%= link_to 'Back', dogs_path %>
122
+
123
+
124
+
9
125
  ```
10
126
 
11
-
12
-
13
- <h3>犬情報一覧</h3>
14
-
15
-
16
-
17
- <table>
18
-
19
- <thead>
20
-
21
- <tr>
22
-
23
-  <th>写真</th>
24
-
25
- <th>id</th>
26
-
27
- <th>名前</th>
28
-
29
- <th>犬種</th>
30
-
31
- <th>年齢</th>
32
-
33
- <th>一言紹介</th>
34
-
35
- <th>性格</th>
36
-
37
- <th>住所</th>
38
-
39
- </tr>
40
-
41
- </thead>
42
-
43
-
44
-
45
- <tbody>
46
-
47
- <% @dogs.each do |dog| %>
48
-
49
- <tr>
50
-
51
- <td> <%= image_tag @dogs.image ,class:'dog-image'%></td>
52
-
53
- <td>No.<%= dog.id %></td>
54
-
55
- <td><%= dog.name %>ちゃん</td>
56
-
57
- <td><%= dog.kind %></td>
58
-
59
- <td><%= dog.old %>歳</td>
60
-
61
- <td><%= dog.dog_pr %></td>
62
-
63
- <td><%= dog.personality %></td>
64
-
65
- <td><%= dog.address %></td>
66
-
67
- </tr>
68
-
69
- <% end %>
70
-
71
- </tbody>
72
-
73
- </table>
74
-
75
-
76
-
77
- <p><%= link_to "ワンちゃん新規登録", :new_dog %></p>
78
-
79
-
80
-
81
- ```show.html.erb
82
-
83
-
84
-
85
-
86
-
87
- <p id="notice"><%= notice %></p>
88
-
89
-
90
-
91
- <div class="dog-show-wrap">
92
-
93
- <div class="dog-show-image">
94
-
95
- <%= image_tag @dog.image ,class:'dog-show-image'%>
96
-
97
- </div>
98
-
99
- <div class="dog-show-text">
100
-
101
- <p class="showText"><%= @dog.name %>ちゃん</p>
102
-
103
- <p class="showText"><%= @dog.old %></p>
104
-
105
- <p class="showText"><%= @dog.kind %></p>
106
-
107
- <p class="showText"><%= @dog.dog_pr %></p>
108
-
109
- <p class="showText"><%= @dog.personality %></p>
110
-
111
- <p class="showText"><%= @dog.address %></p>
112
-
113
- </div>
114
-
115
- </div>
116
-
117
-
118
-
119
- <%= link_to 'Edit', edit_dog_path(@dog) %> |
120
-
121
- <%= link_to 'Back', dogs_path %>
127
+ dogs_controllers
128
+
129
+ ```ここに言語を入力
130
+
131
+ class DogsController < ApplicationController
132
+
133
+ before_action :set_dog, only: %i[ show edit update destroy ]
134
+
135
+
136
+
137
+ # GET /dogs or /dogs.json
138
+
139
+ def index
140
+
141
+ @dogs = Dog.all
142
+
143
+ end
144
+
145
+
146
+
147
+ # GET /dogs/1 or /dogs/1.json
148
+
149
+ def show
150
+
151
+ end
152
+
153
+
154
+
155
+ # GET /dogs/new
156
+
157
+ def new
158
+
159
+ @dog = Dog.new
160
+
161
+ end
162
+
163
+
164
+
165
+ # GET /dogs/1/edit
166
+
167
+ def edit
168
+
169
+ end
170
+
171
+
172
+
173
+ # POST /dogs or /dogs.json
174
+
175
+ def create
176
+
177
+ @dog = Dog.new(dog_params)
178
+
179
+
180
+
181
+ respond_to do |format|
182
+
183
+ if @dog.save
184
+
185
+ format.html { redirect_to dog_url(@dog), notice: "Dog was successfully created." }
186
+
187
+ format.json { render :show, status: :created, location: @dog }
188
+
189
+ else
190
+
191
+ format.html { render :new, status: :unprocessable_entity }
192
+
193
+ format.json { render json: @dog.errors, status: :unprocessable_entity }
194
+
195
+ end
196
+
197
+ end
198
+
199
+ end
200
+
201
+
202
+
203
+ # PATCH/PUT /dogs/1 or /dogs/1.json
204
+
205
+ def update
206
+
207
+ respond_to do |format|
208
+
209
+ if @dog.update(dog_params)
210
+
211
+ format.html { redirect_to dog_url(@dog), notice: "Dog was successfully updated." }
212
+
213
+ format.json { render :show, status: :ok, location: @dog }
214
+
215
+ else
216
+
217
+ format.html { render :edit, status: :unprocessable_entity }
218
+
219
+ format.json { render json: @dog.errors, status: :unprocessable_entity }
220
+
221
+ end
222
+
223
+ end
224
+
225
+ end
226
+
227
+
228
+
229
+ # DELETE /dogs/1 or /dogs/1.json
230
+
231
+ def destroy
232
+
233
+ @dog.destroy
234
+
235
+
236
+
237
+ respond_to do |format|
238
+
239
+ format.html { redirect_to dogs_url, notice: "Dog was successfully destroyed." }
240
+
241
+ format.json { head :no_content }
242
+
243
+ end
244
+
245
+ end
246
+
247
+
248
+
249
+ private
250
+
251
+ # Use callbacks to share common setup or constraints between actions.
252
+
253
+ def set_dog
254
+
255
+ @dog = Dog.find(params[:id])
256
+
257
+ end
258
+
259
+
260
+
261
+ # Only allow a list of trusted parameters through.
262
+
263
+ def dog_params
264
+
265
+ params.require(:dog).permit(:name,:kind,:address,:old,:dog_pr,:personality,:image)
266
+
267
+ end
268
+
269
+ end
122
270
 
123
271
 
124
272
 
@@ -126,145 +274,15 @@
126
274
 
127
275
 
128
276
 
277
+ models/dogs.rb
278
+
129
- ```ここに言語を入力 dogs_controller.rb
279
+ ```ここに言語を入力models/dogs.rb
130
-
280
+
281
+
282
+
131
- class DogsController < ApplicationController
283
+ class Dog < ApplicationRecord
132
-
133
- before_action :set_dog, only: %i[ show edit update destroy ]
284
+
134
-
135
-
136
-
137
- # GET /dogs or /dogs.json
138
-
139
- def index
140
-
141
- @dogs = Dog.all
142
-
143
- end
144
-
145
-
146
-
147
- # GET /dogs/1 or /dogs/1.json
148
-
149
- def show
150
-
151
- end
152
-
153
-
154
-
155
- # GET /dogs/new
156
-
157
- def new
158
-
159
- @dog = Dog.new
160
-
161
- end
162
-
163
-
164
-
165
- # GET /dogs/1/edit
166
-
167
- def edit
168
-
169
- end
170
-
171
-
172
-
173
- # POST /dogs or /dogs.json
174
-
175
- def create
176
-
177
- @dog = Dog.new(dog_params)
178
-
179
-
180
-
181
- respond_to do |format|
285
+ has_one_attached :image
182
-
183
- if @dog.save
184
-
185
- format.html { redirect_to dog_url(@dog), notice: "Dog was successfully created." }
186
-
187
- format.json { render :show, status: :created, location: @dog }
188
-
189
- else
190
-
191
- format.html { render :new, status: :unprocessable_entity }
192
-
193
- format.json { render json: @dog.errors, status: :unprocessable_entity }
194
-
195
- end
196
-
197
- end
198
-
199
- end
200
-
201
-
202
-
203
- # PATCH/PUT /dogs/1 or /dogs/1.json
204
-
205
- def update
206
-
207
- respond_to do |format|
208
-
209
- if @dog.update(dog_params)
210
-
211
- format.html { redirect_to dog_url(@dog), notice: "Dog was successfully updated." }
212
-
213
- format.json { render :show, status: :ok, location: @dog }
214
-
215
- else
216
-
217
- format.html { render :edit, status: :unprocessable_entity }
218
-
219
- format.json { render json: @dog.errors, status: :unprocessable_entity }
220
-
221
- end
222
-
223
- end
224
-
225
- end
226
-
227
-
228
-
229
- # DELETE /dogs/1 or /dogs/1.json
230
-
231
- def destroy
232
-
233
- @dog.destroy
234
-
235
-
236
-
237
- respond_to do |format|
238
-
239
- format.html { redirect_to dogs_url, notice: "Dog was successfully destroyed." }
240
-
241
- format.json { head :no_content }
242
-
243
- end
244
-
245
- end
246
-
247
-
248
-
249
- private
250
-
251
- # Use callbacks to share common setup or constraints between actions.
252
-
253
- def set_dog
254
-
255
- @dog = Dog.find(params[:id])
256
-
257
- end
258
-
259
-
260
-
261
- # Only allow a list of trusted parameters through.
262
-
263
- def dog_params
264
-
265
- params.require(:dog).permit(:name,:kind,:address,:old,:dog_pr,:personality,:image)
266
-
267
- end
268
286
 
269
287
  end
270
288
 
@@ -272,30 +290,14 @@
272
290
 
273
291
  ```
274
292
 
275
-
293
+ routes.rb
276
-
294
+
277
- ```ここに言語を入力models/dogs.rb
295
+ ```routes.rb
278
-
279
-
280
-
296
+
281
- class Dog < ApplicationRecord
297
+ Rails.application.routes.draw do
282
-
298
+
283
- has_one_attached :image
299
+ resources :dogs
284
-
300
+
285
- end
301
+ end
286
-
287
-
288
302
 
289
303
  ```
290
-
291
-
292
-
293
- ```routes.rb
294
-
295
- Rails.application.routes.draw do
296
-
297
- resources :dogs
298
-
299
- end
300
-
301
- ```