From 70852d12842f61aa2885528714f1c4f2a7280b9c Mon Sep 17 00:00:00 2001 From: Nikita Kholin Date: Sun, 23 Jul 2017 21:44:51 +0300 Subject: [PATCH] Fix unscoped issue --- app/controllers/room_activities_controller.rb | 2 +- app/controllers/rooms_controller.rb | 2 +- app/models/room.rb | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/room_activities_controller.rb b/app/controllers/room_activities_controller.rb index f77e943..222278b 100644 --- a/app/controllers/room_activities_controller.rb +++ b/app/controllers/room_activities_controller.rb @@ -3,7 +3,7 @@ class RoomActivitiesController < ApplicationController before_action :require_room_presence def new - @room_activities = @room.room_activities.unscoped + @room_activities = @room.room_activities_with_disabled end def create diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index cece5c6..9193334 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -24,7 +24,7 @@ def create end def edit - @room_activities = @room.room_activities.unscoped + @room_activities = @room.room_activities_with_disabled end def update diff --git a/app/models/room.rb b/app/models/room.rb index 1b0c62b..2a5e838 100644 --- a/app/models/room.rb +++ b/app/models/room.rb @@ -11,6 +11,10 @@ def activities Activity.where(room_activity_id: room_activity_ids) end + def room_activities_with_disabled + RoomActivity.where(room_id: id) + end + def create_default_room_activities RoomActivity::DEFAULT_ROOM_ACTIVITIES.map do |activity_name| room_activities.create(name: activity_name)