質問編集履歴
1
ソースコードを画像を消して記入しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -16,10 +16,117 @@
|
|
16
16
|
```Ruby
|
17
17
|
createアクションはpostcontrollerに記載済みでした。
|
18
18
|
ソースコード
|
19
|
+
class PostsController < ApplicationController
|
20
|
+
#before_action :authenticate_user!
|
21
|
+
def index
|
19
|
-
|
22
|
+
#@posts=Post.all.order(created_at: :desc)
|
20
|
-
|
23
|
+
@post=Post.where(genre: '日本映画・ドラマ')
|
21
|
-
|
24
|
+
end
|
22
25
|
|
26
|
+
def indexb
|
27
|
+
@postb=Post.where(genre: '韓国映画・ドラマ')
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
def indexc
|
32
|
+
@postc=Post.where(genre: '海外ドラマ')
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def indexd
|
37
|
+
@postd=Post.where(genre: '海外映画')
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
def new
|
44
|
+
@post=Post.new
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def create
|
49
|
+
@post=Post.new(post_params)
|
50
|
+
if @post.save
|
51
|
+
redirect_to controller: :home, action: :top
|
52
|
+
else
|
53
|
+
redirect_to controller: :posts, action: :new
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
private
|
60
|
+
def post_params
|
61
|
+
params.require(:post).permit(:genre,:title,:released_year,:image,:summary,:director,:cast,:casta,:castb)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
**nwe.html.erb**
|
67
|
+
<div class="posts-new">
|
68
|
+
<div class="form-container">
|
69
|
+
<h1 class="form-heading">Tell Your Favotite!</h1>
|
70
|
+
<div class="form-content">
|
71
|
+
<%= form_with model: @post,url: {controller:'posts',action: 'create'} do |form| %>
|
72
|
+
<%= form.radio_button :genre, :"日本映画・ドラマ"%>
|
73
|
+
<%= form.label :genre,"日本映画・ドラマ",{style: "display: inline-block;"}%>
|
74
|
+
<%= form.radio_button :genre, :"韓国映画・ドラマ"%>
|
75
|
+
<%= form.label :genre,"韓国映画・ドラマ",{style: "display: inline-block;"}%>
|
76
|
+
<%= form.radio_button :genre, :"海外ドラマ"%>
|
77
|
+
<%= form.label :genre,"海外ドラマ",{style: "display: inline-block;"}%>
|
78
|
+
<%= form.radio_button :genre, :"海外映画"%>
|
79
|
+
<%= form.label :genre,"海外映画",{style: "display: inline-block;"}%>
|
80
|
+
<br>
|
81
|
+
<br>
|
82
|
+
<%= form.label :title,"~タイトル~ " %><br>
|
83
|
+
<%= form.text_field :title,class:"m-title",size:"40"%>
|
84
|
+
<br>
|
85
|
+
<br>
|
86
|
+
<%= form.label :released_year,"~公開年~"%><br>
|
87
|
+
<%= form.date_select :released_year,{start_year: 2020,end_year:2020-40,discard_month:true,discard_day:true},class:"released-year"%>
|
88
|
+
<br>
|
89
|
+
<br>
|
90
|
+
<%= form.label :image,"~画像~"%><br>
|
91
|
+
<%= form.file_field :image %>
|
92
|
+
<br>
|
93
|
+
<br>
|
94
|
+
<%= form.label :summary,"~あらすじ・レビュー~"%><br>
|
95
|
+
<%= form.text_area :summary,class:"m-summary",size:"40x20"%>
|
96
|
+
<br>
|
97
|
+
<br>
|
98
|
+
<%= form.label :director,"~監督名~"%><br>
|
99
|
+
<%= form.text_field :director,class:"m-director",size: 40%>
|
100
|
+
<br>
|
101
|
+
<br>
|
102
|
+
<%= form.label :cast,"~キャスト名~"%><br>
|
103
|
+
<%= form.text_field :cast,class:"m-cast1",size: 40%><br>
|
104
|
+
<%= form.text_field :casta,class:"m-cast2",size: 40%><br>
|
105
|
+
<%= form.text_field :castb,class:"m-cast3",size: 40%>
|
106
|
+
<br>
|
107
|
+
<br>
|
108
|
+
<div class="m-submit">
|
109
|
+
<%= form.submit "投稿",class:"submit"%>
|
110
|
+
</div>
|
111
|
+
<%end%>
|
112
|
+
|
113
|
+
</div>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
</div>
|
117
|
+
|
118
|
+
|
119
|
+
**routes.rb**
|
120
|
+
Rails.application.routes.draw do
|
121
|
+
devise_for :users
|
122
|
+
|
123
|
+
get "/" => "home#top"
|
124
|
+
|
125
|
+
|
126
|
+
resources :posts, only: [:index, :indexb, :indexc, :indexd, :new, :create]
|
127
|
+
|
128
|
+
end
|
129
|
+
|
23
130
|
### 試したこと
|
24
131
|
投稿時のジャンル分けの方法としては、index,indexb,indexc,indexdのようにアクションを4つ作りそれぞれのviewで表示されるようにしています。
|
25
132
|
|