質問編集履歴

2

コードの追加

2021/09/22 01:28

投稿

sk77
sk77

スコア3

test CHANGED
File without changes
test CHANGED
@@ -40,7 +40,171 @@
40
40
 
41
41
 
42
42
 
43
+
44
+
45
+
46
+
47
+
48
+
49
+ ```ここに言語を入力
50
+
51
+
52
+
53
+ ```Rails.application.routes.draw do
54
+
55
+
56
+
57
+ devise_for :users
58
+
59
+ resources :users, only: [:show]
60
+
61
+
62
+
63
+ get 'hello/index' => 'hello#index'
64
+
65
+ get 'hello/link' => 'hello#link'
66
+
67
+ get 'posts' => 'posts#index'
68
+
69
+ get 'posts/new' => 'posts#new'
70
+
71
+ post 'posts' => 'posts#create'
72
+
73
+ get 'posts/:id' => 'posts#show',as: 'post'
74
+
75
+ patch 'posts/:id' => 'posts#update'
76
+
77
+ delete 'posts/:id' => 'posts#destroy'
78
+
79
+ delete 'users/:id' => 'users#destroy'
80
+
81
+ get 'posts/:id/edit' => 'posts#edit', as:'edit_post'
82
+
83
+ root 'posts#index'
84
+
85
+ resources :posts
86
+
87
+
88
+
89
+ end
90
+
91
+
92
+
93
+ ```
94
+
95
+ ```ここに言語を入力
96
+
97
+ class PostsController < ApplicationController
98
+
99
+ before_action :authenticate_user!, except: [:index, :show]
100
+
101
+
102
+
103
+ def index
104
+
105
+ @posts = Post.all
106
+
107
+ @posts = params[:tag_id].present? ? Tag.find(params[:tag_id]).posts : Post.all
108
+
109
+ end
110
+
111
+
112
+
113
+ def new
114
+
115
+ @post = Post.new
116
+
117
+ end
118
+
119
+
120
+
121
+ def create
122
+
123
+ post = Post.new(post_params)
124
+
125
+
126
+
127
+ post.user_id = current_user.id
128
+
129
+
130
+
131
+ if post.save
132
+
133
+ redirect_to :action => "index"
134
+
135
+ else
136
+
137
+ redirect_to :action => "new"
138
+
139
+ end
140
+
141
+ end
142
+
143
+
144
+
145
+ def show
146
+
147
+ @post = Post.find(params[:id])
148
+
149
+ end
150
+
151
+
152
+
153
+ def edit
154
+
155
+ @post = Post.find(params[:id])
156
+
157
+ end
158
+
159
+
160
+
161
+ def update
162
+
163
+ post = Post.find(params[:id])
164
+
165
+ if post.update(post_params)
166
+
167
+ redirect_to :action => "show", :id => post.id
168
+
169
+ else
170
+
171
+ redirect_to :action => "new"
172
+
173
+ end
174
+
175
+ end
176
+
177
+
178
+
179
+ def destroy
180
+
181
+ post = Post.find(params[:id])
182
+
183
+ post.destroy
184
+
185
+ redirect_to user_path
186
+
187
+ end
188
+
189
+
190
+
191
+ private
192
+
193
+ def post_params
194
+
195
+ params.require(:post).permit(:start, :address, :store_name, :latitude, :longitude, :city, :end, :parking, tag_ids:[])
196
+
197
+ end
198
+
199
+ end
200
+
201
+
202
+
203
+ ```
204
+
205
+ ```ここに言語を入力
206
+
43
- ```app/views/users_show.html
207
+ app/view/users/show.html.erb
44
208
 
45
209
 
46
210
 
@@ -90,163 +254,115 @@
90
254
 
91
255
  <% end %>
92
256
 
93
-
94
-
95
-
96
-
97
- ```ここに言語を入力
98
-
99
-
100
-
101
- ```Rails.application.routes.draw do
102
-
103
-
104
-
105
- devise_for :users
106
-
107
- resources :users, only: [:show]
108
-
109
-
110
-
111
- get 'hello/index' => 'hello#index'
112
-
113
- get 'hello/link' => 'hello#link'
114
-
115
- get 'posts' => 'posts#index'
116
-
117
- get 'posts/new' => 'posts#new'
118
-
119
- post 'posts' => 'posts#create'
120
-
121
- get 'posts/:id' => 'posts#show',as: 'post'
122
-
123
- patch 'posts/:id' => 'posts#update'
124
-
125
- delete 'posts/:id' => 'posts#destroy'
126
-
127
- delete 'users/:id' => 'users#destroy'
128
-
129
- get 'posts/:id/edit' => 'posts#edit', as:'edit_post'
130
-
131
- root 'posts#index'
132
-
133
- resources :posts
134
-
135
-
136
-
137
- end
138
-
139
-
140
-
141
- ```
142
-
143
- ```ここに言語を入力
144
-
145
- class PostsController < ApplicationController
146
-
147
- before_action :authenticate_user!, except: [:index, :show]
148
-
149
-
150
-
151
- def index
152
-
153
- @posts = Post.all
154
-
155
- @posts = params[:tag_id].present? ? Tag.find(params[:tag_id]).posts : Post.all
156
-
157
- end
158
-
159
-
160
-
161
- def new
162
-
163
- @post = Post.new
164
-
165
- end
166
-
167
-
168
-
169
- def create
170
-
171
- post = Post.new(post_params)
172
-
173
-
174
-
175
- post.user_id = current_user.id
176
-
177
-
178
-
179
- if post.save
180
-
181
- redirect_to :action => "index"
182
-
183
- else
184
-
185
- redirect_to :action => "new"
186
-
187
- end
188
-
189
- end
190
-
191
-
192
-
193
- def show
194
-
195
- @post = Post.find(params[:id])
196
-
197
- end
198
-
199
-
200
-
201
- def edit
202
-
203
- @post = Post.find(params[:id])
204
-
205
- end
206
-
207
-
208
-
209
- def update
210
-
211
- post = Post.find(params[:id])
212
-
213
- if post.update(post_params)
214
-
215
- redirect_to :action => "show", :id => post.id
216
-
217
- else
218
-
219
- redirect_to :action => "new"
220
-
221
- end
222
-
223
- end
224
-
225
-
226
-
227
- def destroy
228
-
229
- post = Post.find(params[:id])
230
-
231
- post.destroy
232
-
233
- redirect_to user_path
234
-
235
- end
236
-
237
-
238
-
239
- private
240
-
241
- def post_params
242
-
243
- params.require(:post).permit(:start, :address, :store_name, :latitude, :longitude, :city, :end, :parking, tag_ids:[])
244
-
245
- end
246
-
247
- end
248
-
249
-
257
+ <%= link_to "一覧に戻る", posts_path %>
258
+
259
+
260
+
261
+ ```
262
+
263
+ ```ここに言語を入力
264
+
265
+ app/views/posts/show.html.reb
266
+
267
+
268
+
269
+ <h1>コンビニMAP</h1>
270
+
271
+ <h3>投稿内容詳細</h3>
272
+
273
+ <div class="post">
274
+
275
+ <p>ユーザネーム:<%= @post.user.name %></p>
276
+
277
+ <p>住所:<%= @post.address %></p>
278
+
279
+ <p>店名:<%= @post.store_name %></p>
280
+
281
+ <p>駐車場有無:<%= @post.parking %></p>
282
+
283
+ <p>営業時間:<%= @post.start.strftime("%H:%M") %> <%= @post.end.strftime("%H:%M") %></p>
284
+
285
+ <p>投稿日:<%= @post.created_at.strftime("%m月 %d日") %></p>
286
+
287
+ <%= link_to " 編集する", edit_post_path(@post.id) %>
288
+
289
+ <br><%= link_to "一覧に戻る", posts_path %>
290
+
291
+ <p>
292
+
293
+ </div>
294
+
295
+ ```
296
+
297
+ ```ここに言語を入力
298
+
299
+ app/views/posts/index.html.erb
300
+
301
+
302
+
303
+ <br>
304
+
305
+ <a href="/users/sign_in">ログイン</a><br />
306
+
307
+ <%= link_to "新規登録", new_user_registration_path %>
308
+
309
+
310
+
311
+ <p><%= button_to 'ログアウト', destroy_user_session_path, method: :delete %>
312
+
313
+ <% if user_signed_in? %>
314
+
315
+ <%= link_to "マイページへ", user_path(current_user.id) %> 
316
+
317
+ <% end %>
318
+
319
+
320
+
321
+ <h1>コンビニMAP</h1>
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+ <h3>投稿一覧</h3>
330
+
331
+ <p><%= link_to "新しくコンビニを投稿する", posts_new_path %>
332
+
333
+ <div class="posts-container">
334
+
335
+ <% @posts.each do |t| %>
336
+
337
+ <a href="/users/<%= t.user.id %>"><%= t.user.name %></a>
338
+
339
+ <div class="post">
340
+
341
+ <%= t.created_at.strftime("%m月 %d日") %>
342
+
343
+ <%= t.city %>
344
+
345
+ <%= t.address %>
346
+
347
+ <tr>
348
+
349
+ <td><%= link_to "詳細へ", post_path(t.id) %></td>
350
+
351
+ </tr>
352
+
353
+ </div>
354
+
355
+ <% end %>
356
+
357
+ </div>
358
+
359
+ <div class="field">
360
+
361
+ <input id="address" type="textbox" value="">
362
+
363
+ <input type="button" value="場所を地図で表示" onclick="codeAddress()">
364
+
365
+ </div>
250
366
 
251
367
  ```
252
368
 

1

urlを消した

2021/09/22 01:28

投稿

sk77
sk77

スコア3

test CHANGED
File without changes
test CHANGED
@@ -106,7 +106,7 @@
106
106
 
107
107
  resources :users, only: [:show]
108
108
 
109
- # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
109
+
110
110
 
111
111
  get 'hello/index' => 'hello#index'
112
112