質問編集履歴

1

情報が不足しており、失礼しました。モデルの情報も追加致しました。

2015/11/12 04:29

投稿

Auc_fan
Auc_fan

スコア17

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,42 @@
18
18
 
19
19
  ```rails
20
20
 
21
+ **Show**
22
+
23
+ <p>
24
+
25
+ <strong>Content2:</strong>
26
+
27
+ <%# @campaign.content2.try(:) %>
28
+
29
+ <%# @campaign.content2 %>
30
+
31
+ <%= text_field_tag 'campaign[content2][]' %>
32
+
33
+ </p>
34
+
35
+
36
+
37
+ **new**
38
+
39
+ <%= form_for(@campaign) do |f| %>
40
+
41
+ <div class="field">
42
+
43
+ <%= f.label :title %><br>
44
+
45
+ <%= f.text_field :title %>
46
+
47
+ </div>
48
+
49
+ <div class="field">
50
+
51
+ <%= f.label :content1 %><br>
52
+
53
+ <%= f.text_field :content1 %>
54
+
55
+ </div>
56
+
21
57
  <div class="field">
22
58
 
23
59
  <%= f.label :content2 %><br>
@@ -28,17 +64,115 @@
28
64
 
29
65
  </div>
30
66
 
67
+ <div class="actions">
68
+
69
+ <%= f.submit %>
70
+
71
+ </div>
72
+
73
+ <% end %>
74
+
31
75
  ```
32
76
 
33
77
  ■Controller
34
78
 
35
79
  ```ここに言語を入力
36
80
 
81
+ **create**
82
+
83
+ def create
84
+
85
+ @campaign = Campaign.new(campaign_params)
86
+
87
+
88
+
89
+ respond_to do |format|
90
+
91
+ if @campaign.save
92
+
93
+ format.html { redirect_to @campaign, notice: 'Campaign was successfully created.' }
94
+
95
+ format.json { render :show, status: :created, location: @campaign }
96
+
97
+ else
98
+
99
+ format.html { render :new }
100
+
101
+ format.json { render json: @campaign.errors, status: :unprocessable_entity }
102
+
103
+ end
104
+
105
+ end
106
+
107
+ end
108
+
109
+
110
+
111
+ **Update**
112
+
113
+ def update
114
+
115
+ respond_to do |format|
116
+
117
+ if @campaign.update(campaign_params)
118
+
119
+ format.html { redirect_to @campaign, notice: 'Campaign was successfully updated.' }
120
+
121
+ format.json { render :show, status: :ok, location: @campaign }
122
+
123
+ else
124
+
125
+ format.html { render :edit }
126
+
127
+ format.json { render json: @campaign.errors, status: :unprocessable_entity }
128
+
129
+ end
130
+
131
+ end
132
+
133
+ end
134
+
135
+
136
+
137
+ **strong parameter**
138
+
37
139
  def campaign_params
38
140
 
39
141
  params.require(:campaign).permit(:title, :content1, :content2 => [])
40
142
 
41
143
  end
144
+
145
+ ```
146
+
147
+
148
+
149
+ ■model
150
+
151
+ ```
152
+
153
+ **db**
154
+
155
+ create_table "campaigns", force: :cascade do |t|
156
+
157
+ t.string "title"
158
+
159
+ t.string "content1"
160
+
161
+ t.string "content2"
162
+
163
+ t.datetime "created_at", null: false
164
+
165
+ t.datetime "updated_at", null: false
166
+
167
+ end
168
+
169
+
170
+
171
+ **model**
172
+
173
+ class Campaign < ActiveRecord::Base
174
+
175
+ end
42
176
 
43
177
  ```
44
178