This is a pretty general question, and will involve more than just simple Rails actions. It also depends on what you mean by approve this information
. Do you as the administrator just want to make sure it is valid info (e.g. the user didn't type a bunch of random characters in a phone number field) or do you need to actually make sure the information itself is acceptable (e.g. the user didn't enter a bunch of profanity into a text box)?
For the first part, you can use Active Record Validations to make sure the data itself is sound (like verifying that a phone number actually consists of numbers).
For the second part, you will need to track whether or not the information should be displayed on your site. I don't know what data model you've set up, but let's say that the entirety of what the user is submitting is called a review
.
To track whether or not this review should be displayed, you will want to add an approved
attribute to the Review
model. You can do this through an Active Record Migration. When a new review is created, approved
should be false
by default. Once you are ready to show this new review, you can set approved
to true
.
You can accomplish all of this through a few controller actions. I'll assume you have an admin
flag on your personal user account so that you can approve reviews. If so, you could set up a controller like so:
class ReviewController < ActionController::Base
def index
if current_user.admin
# Allow yourself to view all Reviews, presumably with an `Approve` button
@reviews = Review.all
else
# Only allow standard users to see already-approved reviews
@reviews = Review.where(approved: true)
end
# render reviews however you need to
end
def update
@review = Review.find(params[:id])
if params[:approved] && current_user.admin
# You've clicked an approve button, and you are an admin
@review.update_attribute(:approved, true)
end
# respond to the request here
# Note, there are definitely cleaner ways to do this, but I wanted to
# demonstrate where you could set the approved flag
end
end