Skip to content

Commit

Permalink
Add join_room method back
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlON committed Jul 30, 2017
1 parent 6a1047d commit e674bfb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/room_requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/rooms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e674bfb

Please sign in to comment.