So my question is how to render the show template only if the entity belongs to the current user. I have this code in my controller
def show
respond_with(@site) if current_user.author_of?(@site)
end
But it still renders the show template. What is the right approach?
@site is this one
def find_site
@site = Site.find(params[:id])
end
The best place to put this logic is within the
find_site
method.Scope the query to the user. Assuming your relationship is
user has_many sites
, the following code will work:@site = current_user.sites.find(params[:id])