Skip to content

Commit

Permalink
Fix room activity update when it's disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
hmlON committed Jul 23, 2017
1 parent 50ecd34 commit de02daa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 4 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
$(document).on('turbolinks:load', function() {
$(".alert").fadeIn(0).delay(5000).fadeOut(500);
$(".js-update-room-activity").click(function (e) {
console.log(this);
$.ajax({
method: "PATCH",
url: "/room_activities/" + $(this).data("id"),
data: { room_activity: { enabled: this.checked } }
})
.done(function( msg ) {
console.log( msg );
alert( "Updated");
})
.fail(function( msg ) {
console.log( msg );
});
});
});
Expand Down
10 changes: 6 additions & 4 deletions app/controllers/room_activities_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ def create
end

def update
room_activity = RoomActivity.find(params[:id])
room_activity.update(room_activity_params)
# respond
room_activity = RoomActivity.unscoped.find(params[:id])
if room_activity.update(room_activity_params)
render json: { ok: true }
else
render json: room_activity.errors
end
end

def destroy
Expand All @@ -43,6 +46,5 @@ def room_activity_params
params.require(:room_activity)
.permit(:name, :enabled)
.merge(room_id: @room.id)
# .tap { |params| params[:creator_id] = current_user.id }
end
end

0 comments on commit de02daa

Please sign in to comment.