2010-09-24 2 views
0

Comment rendre un show show sous certaines conditions?rails conditionnel show

def show 
    @post = Post.find_approved 
    if @post.approved 
     approved = true 
    end 
    respond_to do |format| 
    # I only want to render show.html.erb if approved is true if not I would like to redirect the user back to where he came from 
    end 
end 

Répondre

1
redirect_to :back unless approved 
respond_to do |format| 
    render whatever 
end 
+0

les deux réponses fonctionnent bien. Merci – badnaam

0

Vous pouvez le faire sans intermédiaire approved variable.

@post = Post.find_approved 
    if @post.approved 
    render :action => 'show' 
    else 
    redirect_to your_url_here 
    end