質問編集履歴

1

ソースコードを画像を消して記入しました

2020/05/16 04:02

投稿

tomotomo_1D
tomotomo_1D

スコア4

test CHANGED
File without changes
test CHANGED
@@ -34,11 +34,225 @@
34
34
 
35
35
  ソースコード
36
36
 
37
+ class PostsController < ApplicationController
38
+
39
+ #before_action :authenticate_user!
40
+
41
+ def index
42
+
37
- ![posts_controller](dc9d86300daf32b25eddbfa45290c149.png)
43
+ #@posts=Post.all.order(created_at: :desc)
38
-
44
+
39
- ![新規投稿ページのview](7e12ab25fa2bf30706eb969f4585a7f3.png)
45
+ @post=Post.where(genre: '日本映画・ドラマ')
46
+
40
-
47
+ end
48
+
49
+
50
+
51
+ def indexb
52
+
53
+ @postb=Post.where(genre: '韓国映画・ドラマ')
54
+
55
+
56
+
57
+ end
58
+
59
+
60
+
61
+ def indexc
62
+
63
+ @postc=Post.where(genre: '海外ドラマ')
64
+
65
+
66
+
67
+ end
68
+
69
+
70
+
71
+ def indexd
72
+
73
+ @postd=Post.where(genre: '海外映画')
74
+
75
+
76
+
77
+ end
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+ def new
86
+
87
+ @post=Post.new
88
+
89
+
90
+
91
+ end
92
+
93
+
94
+
95
+ def create
96
+
97
+ @post=Post.new(post_params)
98
+
99
+ if @post.save
100
+
101
+ redirect_to controller: :home, action: :top
102
+
103
+ else
104
+
41
- ![routes.rb](b6cf2fb35b6ffd39c1c4d3d1986ae7f4.png)
105
+ redirect_to controller: :posts, action: :new
106
+
107
+ end
108
+
109
+ end
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ private
118
+
119
+ def post_params
120
+
121
+ params.require(:post).permit(:genre,:title,:released_year,:image,:summary,:director,:cast,:casta,:castb)
122
+
123
+ end
124
+
125
+ end
126
+
127
+
128
+
129
+
130
+
131
+ **nwe.html.erb**
132
+
133
+ <div class="posts-new">
134
+
135
+ <div class="form-container">
136
+
137
+ <h1 class="form-heading">Tell Your Favotite!</h1>
138
+
139
+ <div class="form-content">
140
+
141
+ <%= form_with model: @post,url: {controller:'posts',action: 'create'} do |form| %>
142
+
143
+ <%= form.radio_button :genre, :"日本映画・ドラマ"%>
144
+
145
+ <%= form.label :genre,"日本映画・ドラマ",{style: "display: inline-block;"}%>
146
+
147
+ <%= form.radio_button :genre, :"韓国映画・ドラマ"%>
148
+
149
+ <%= form.label :genre,"韓国映画・ドラマ",{style: "display: inline-block;"}%>
150
+
151
+ <%= form.radio_button :genre, :"海外ドラマ"%>
152
+
153
+ <%= form.label :genre,"海外ドラマ",{style: "display: inline-block;"}%>
154
+
155
+ <%= form.radio_button :genre, :"海外映画"%>
156
+
157
+ <%= form.label :genre,"海外映画",{style: "display: inline-block;"}%>
158
+
159
+ <br>
160
+
161
+ <br>
162
+
163
+ <%= form.label :title,"~タイトル~ " %><br>
164
+
165
+ <%= form.text_field :title,class:"m-title",size:"40"%>
166
+
167
+ <br>
168
+
169
+ <br>
170
+
171
+ <%= form.label :released_year,"~公開年~"%><br>
172
+
173
+ <%= form.date_select :released_year,{start_year: 2020,end_year:2020-40,discard_month:true,discard_day:true},class:"released-year"%>
174
+
175
+ <br>
176
+
177
+ <br>
178
+
179
+ <%= form.label :image,"~画像~"%><br>
180
+
181
+ <%= form.file_field :image %>
182
+
183
+ <br>
184
+
185
+ <br>
186
+
187
+ <%= form.label :summary,"~あらすじ・レビュー~"%><br>
188
+
189
+ <%= form.text_area :summary,class:"m-summary",size:"40x20"%>
190
+
191
+ <br>
192
+
193
+ <br>
194
+
195
+ <%= form.label :director,"~監督名~"%><br>
196
+
197
+ <%= form.text_field :director,class:"m-director",size: 40%>
198
+
199
+ <br>
200
+
201
+ <br>
202
+
203
+ <%= form.label :cast,"~キャスト名~"%><br>
204
+
205
+ <%= form.text_field :cast,class:"m-cast1",size: 40%><br>
206
+
207
+ <%= form.text_field :casta,class:"m-cast2",size: 40%><br>
208
+
209
+ <%= form.text_field :castb,class:"m-cast3",size: 40%>
210
+
211
+ <br>
212
+
213
+ <br>
214
+
215
+ <div class="m-submit">
216
+
217
+ <%= form.submit "投稿",class:"submit"%>
218
+
219
+ </div>
220
+
221
+ <%end%>
222
+
223
+
224
+
225
+ </div>
226
+
227
+
228
+
229
+ </div>
230
+
231
+ </div>
232
+
233
+
234
+
235
+
236
+
237
+ **routes.rb**
238
+
239
+ Rails.application.routes.draw do
240
+
241
+ devise_for :users
242
+
243
+
244
+
245
+ get "/" => "home#top"
246
+
247
+
248
+
249
+
250
+
251
+ resources :posts, only: [:index, :indexb, :indexc, :indexd, :new, :create]
252
+
253
+
254
+
255
+ end
42
256
 
43
257
 
44
258