I’ve written an Index action that will instantiate objects differently based on what selection the user choses. Here’s the code which better illustrates what I’m talking about:
def index review_type = params[:review_type] if review_type == "1" @count = Review.posted.count @reviews = Review.posted elsif review_type == "2" @count = Review.rejected.count @reviews = Review.rejected # default to display pending reviews else @count = Review.pending.count @reviews = Review.pending.page end end
So basically, the index view page provides the user different selections which display different scopes (in this case, pending, rejected, posted) of the same Model. The choice (here, review_type) is passed through with the
post method when the user clicks the link.
Is there a better way to handle this case? How can this code be improved? Thanks in advance!