In my app, users can write reviews for products. But before publishing the review, the admin needs to accept the review or reject it (allowing the user to change its review).
To manage the validation part, I created the validate method inside the Reviews controller. The admin has two buttons (links) near the new review: Accep, Reject. That buttons redirect to the validate#reviews and send the appropriate parameters: review_id and admin_action (accept or reject).
How do I create the path of the buttons (links)?
I tried many combinations like link_to "accept", polymorphic_path([review, :validate => 'accep']) but without success. I have trouble to figure out how the URL should look like! Of course, I added get 'reviews/validate' to routes.rb before.
If you had in a similar situation, how did you do? Is there best practices?
Update
I also tried link_to "Accept", polymorphic_path(:reviews => review, :validate => 'accept'), but get a Nil location provided. Can’t build URI.
Update 2
I would like to use the validate method (instead of creating two methods accept and reject) because there are common data processing, like getting the review, checking admin auth,…
So, in my controller, I’m looking for something like:
def activate
# Get review, using review_id
# Check in the admin has the right to validate the review
# Execute the correct action: accept or reject.
end
private
def accept
...
end
def reject
...
end
Thanks in advance.
In your routes.rb:
This will make the urls reviews/:id/accept and reviews/:id reject available through the helpers accept_review_path(@review) and reject_review_path(@review).
Last thing, in your ReviewsController add