質問編集履歴

2

フォームオブジェクトモデル追記

2020/11/27 09:16

投稿

souda-takeru
souda-takeru

スコア4

test CHANGED
File without changes
test CHANGED
@@ -248,6 +248,68 @@
248
248
 
249
249
 
250
250
 
251
+ ```events_tag
252
+
253
+ ```ruby
254
+
255
+ class EventsTag
256
+
257
+
258
+
259
+ include ActiveModel::Model
260
+
261
+ attr_accessor :name, :explanation, :facility_id, :scale_id, :category_id, :volunteer, :tagname, :user_id
262
+
263
+
264
+
265
+
266
+
267
+ with_options presence: true do
268
+
269
+ validates :name
270
+
271
+ validates :explanation
272
+
273
+ validates :facility_id
274
+
275
+ validates :scale_id
276
+
277
+ validates :category_id
278
+
279
+ end
280
+
281
+ with_options numericality: { other_than: 1 } do
282
+
283
+ validates :facility_id
284
+
285
+ validates :scale_id
286
+
287
+ validates :category_id
288
+
289
+ end
290
+
291
+
292
+
293
+
294
+
295
+ def save
296
+
297
+ event = Event.create(name: name, explanation: explanation, facility_id: facility_id, scale_id: scale_id, category_id: category_id, volunteer: volunteer,user_id: user_id)
298
+
299
+ tag = Tag.where(tagname: tagname).first_or_initialize
300
+
301
+ tag.save
302
+
303
+
304
+
305
+ EventTagRelation.create(event_id: event.id, tag_id: tag.id)
306
+
307
+ end
308
+
309
+
310
+
311
+ end
312
+
251
313
  ```
252
314
 
253
315
  ```

1

ルーティング追記

2020/11/27 09:16

投稿

souda-takeru
souda-takeru

スコア4

test CHANGED
File without changes
test CHANGED
@@ -224,6 +224,30 @@
224
224
 
225
225
  end
226
226
 
227
+ ```routes
228
+
227
- ```_
229
+ ```ruby
230
+
228
-
231
+ Rails.application.routes.draw do
232
+
233
+ devise_for :users
234
+
235
+ root to: "events#index"
236
+
237
+ resources :events, only: [:new, :create, :show, :destroy, :edit, :update] do
238
+
239
+ collection do
240
+
241
+ get 'search'
242
+
243
+ end
244
+
245
+ end
246
+
247
+ end
248
+
249
+
250
+
229
- ```
251
+ ```
252
+
253
+ ```