YelpDemo - User Admin Rights

I've added /admin/users to the YelpDemo project. In the users view page, I have various user attributes displaying such as First Name, Last Name, Last Log In, Admin, etc... Currently the admin field just displays true or false depending on the user. What would be the best way to go about changing this attribute, and updating the admin column in the user table to true or false? I was thinking to use a dropdown to select true or false, and then update the selection in the database. This page would be a lot easier and quicker to use, rather than having to pull up the console on the server every time to grant or revoke admin rights for a user. I assume that I would also need to create some kind of action in the controller, correct? I've been reading articles and forum posts I've found on Google for the last couple of hours, and haven't found much that's relevant in regards to what I would like to accomplish. Any advise would be appreciated! Thanks! Alan

Posted over 5 years ago by Alan Springle
Posted over 5 years ago by Alex Yang

Yes, you're basically right on target. Every time you want to add a new page or ability, you'll need to add a new action to your controller. I'm not sure about how you've customized your app, but in general, there are two ways to do this:

1) Add a button to toggle On/Off or set up a form that users can submit

These would connect to a new action you'd need to create in your controller to update the database entry. Once it's updated, you'll need to decide where to redirect the user.

2) Do this without having to refresh the page or redirect to a different page

This approach is more complicated, and will require you to use JavaScript. Basically, if a specific action (e.g. clicking a button) is triggered, the database entry will be modified.