Just FYI. This piece of code can be improved.
Original commit by Sharetribe:
https://bitbucket.org/freelensors/freelensia-sharetribe-migration/commits/95db7b4be3220062faaba28ca26f36581fdee71b
This concerns changing status for post_allowed, promote_admin, ban_user. Currently request is redundant. Every time we change 1 status of 1 user (user1), it requests down to server into 2 list requests, alow_post_users = [user1, usern…], disabled_post_users = [user2, user2n]
allowed_post_users( the system takes all users with checkbox checked), disabled_post_users(takes all user with unchecked box) of 1 current page
Corresponding, at the back end code, there are always 2 sql commands call update all,
users.where(id: allow_post_users).update_all(allow_post_listing: 1)
users.where(id: disabled_post_users).update_all(allow_post_listing: 0)
Instead, it is much easier and simplier as follows:
Just pass the id 1 user needs and the value is check 0 or 1 only, and just do 1 sql command, user.find(id: id).update(allow_post_listing: value)