diff --git a/app/controllers/room_requests_controller.rb b/app/controllers/room_requests_controller.rb index 637fdf3..5f3644c 100644 --- a/app/controllers/room_requests_controller.rb +++ b/app/controllers/room_requests_controller.rb @@ -9,7 +9,7 @@ def index end def accept - current_user.room.users << @request.sender + @request.sender.join_room(current_user.room) redirect_to dashboard_path, notice: "#{@request.sender.name} successfully joined your room." end diff --git a/app/controllers/rooms_controller.rb b/app/controllers/rooms_controller.rb index 9193334..a651ec6 100644 --- a/app/controllers/rooms_controller.rb +++ b/app/controllers/rooms_controller.rb @@ -15,7 +15,7 @@ def create @room = Room.new(room_params) if @room.save - @room.users << current_user + current_user.join_room(@room) @room.create_default_room_activities redirect_to new_room_activity_path, notice: "You have successfully created new room \"#{@room.name}\"." else @@ -45,7 +45,7 @@ def join notice: 'To join another room you need to leave your current. You can do this in danger zone.' end room = Room.with_invite_token(params[:token]) - room.users << current_user + current_user.join_room(room) redirect_to dashboard_path, notice: "Welcome to room \"#{room.name}\"!" end diff --git a/app/models/user.rb b/app/models/user.rb index ed105f7..6a97775 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -34,6 +34,10 @@ def next_on_room_activities room_activities.select { |room_activity| room_activity.next_on_user == self } end + def join_room(room) + room.users << self + end + def leave_room activities.destroy_all update(room: nil)