質問編集履歴
3
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -209,3 +209,39 @@
|
|
209
209
|
end
|
210
210
|
|
211
211
|
```
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
###さらに追記
|
216
|
+
|
217
|
+
regist.html.erb
|
218
|
+
|
219
|
+
```ruby
|
220
|
+
|
221
|
+
<h1>New Coordinator</h1>
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
<%= render 'form', coordinator: @coordinator %>
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
<%= link_to 'Back', coordinators_path %>
|
230
|
+
|
231
|
+
```
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
_form.html.erb(一部:section_idのみ)
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
|
239
|
+
<div class="field">
|
240
|
+
|
241
|
+
<%= f.label :section, '事業課' %>
|
242
|
+
|
243
|
+
<%= f.collection_select( :section_id, Section.all, :id, :name, :include_blank => true) %>
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
```
|
2
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -27,3 +27,185 @@
|
|
27
27
|
シンプルに書くにはどのように記述すれば良いでしょうか?
|
28
28
|
|
29
29
|
何卒、よろしくお願い致します。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
###追記
|
34
|
+
|
35
|
+
coordinators_controller.rb
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
|
39
|
+
class CoordinatorsController < ApplicationController
|
40
|
+
|
41
|
+
before_action :set_coordinator, only: [:show, :edit, :update, :destroy]
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
# GET /coordinators
|
46
|
+
|
47
|
+
# GET /coordinators.json
|
48
|
+
|
49
|
+
def index
|
50
|
+
|
51
|
+
@coordinators = Coordinator.all
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
# GET /coordinators/1
|
58
|
+
|
59
|
+
# GET /coordinators/1.json
|
60
|
+
|
61
|
+
def show
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# GET /coordinators/regist
|
68
|
+
|
69
|
+
def regist
|
70
|
+
|
71
|
+
@coordinator = Coordinator.new
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
# GET /coordinators/1/edit
|
78
|
+
|
79
|
+
def edit
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
# POST /coordinators
|
86
|
+
|
87
|
+
# POST /coordinators.json
|
88
|
+
|
89
|
+
def create
|
90
|
+
|
91
|
+
@coordinator = Coordinator.new(coordinator_params)
|
92
|
+
|
93
|
+
respond_to do |format|
|
94
|
+
|
95
|
+
if @coordinator.save
|
96
|
+
|
97
|
+
format.html { redirect_to @coordinator, notice: 'コーディネーター登録完了' }
|
98
|
+
|
99
|
+
#format.json { render :show, status: :created, location: @coordinator }
|
100
|
+
|
101
|
+
else
|
102
|
+
|
103
|
+
format.html { render :regist }
|
104
|
+
|
105
|
+
#format.json { render json: @coordinator.errors, status: :unprocessable_entity }
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
# PATCH/PUT /coordinators/1
|
116
|
+
|
117
|
+
# PATCH/PUT /coordinators/1.json
|
118
|
+
|
119
|
+
def update
|
120
|
+
|
121
|
+
#params[:coordinator][:section_id] = params[:coordinator][:section_id].blank? ? -1 : params[:coordinator][:section_id]
|
122
|
+
|
123
|
+
respond_to do |format|
|
124
|
+
|
125
|
+
if @coordinator.update(coordinator_params)
|
126
|
+
|
127
|
+
format.html { redirect_to @coordinator, notice: 'Coordinator was successfully updated.' }
|
128
|
+
|
129
|
+
format.json { render :show, status: :ok, location: @coordinator }
|
130
|
+
|
131
|
+
else
|
132
|
+
|
133
|
+
format.html { render :edit }
|
134
|
+
|
135
|
+
format.json { render json: @coordinator.errors, status: :unprocessable_entity }
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
# DELETE /coordinators/1
|
146
|
+
|
147
|
+
# DELETE /coordinators/1.json
|
148
|
+
|
149
|
+
def destroy
|
150
|
+
|
151
|
+
@coordinator.destroy
|
152
|
+
|
153
|
+
respond_to do |format|
|
154
|
+
|
155
|
+
format.html { redirect_to coordinators_url, notice: 'Coordinator was successfully destroyed.' }
|
156
|
+
|
157
|
+
format.json { head :no_content }
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
private
|
166
|
+
|
167
|
+
# Use callbacks to share common setup or constraints between actions.
|
168
|
+
|
169
|
+
def set_coordinator
|
170
|
+
|
171
|
+
@coordinator = Coordinator.find(params[:id])
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
# Never trust parameters from the scary internet, only allow the white list through.
|
178
|
+
|
179
|
+
def coordinator_params
|
180
|
+
|
181
|
+
params.require(:coordinator).permit(:name, :name2, :coordinator_id, :password, :mail, :section_id, :department_id, :division_id, :position_id, :profimg, :authority_id, :status, :token, :token_limit, {:office_ids => []})
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
coordinator.rb
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
|
197
|
+
class Coordinator < ApplicationRecord
|
198
|
+
|
199
|
+
after_initialize :set_default
|
200
|
+
|
201
|
+
private
|
202
|
+
|
203
|
+
def set_default
|
204
|
+
|
205
|
+
self.section_id ||= -1
|
206
|
+
|
207
|
+
end
|
208
|
+
|
209
|
+
end
|
210
|
+
|
211
|
+
```
|
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
###現状のコード
|
2
|
+
|
1
3
|
```ruby
|
2
4
|
|
3
5
|
#コントローラー
|