From 3f0737c6141f155d13bdfbe455d6edeb3faa46ad Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Sun, 14 Feb 2021 16:51:55 +0100 Subject: [PATCH] Fix 404 for missing package --- app/controllers/packages_controller.rb | 17 +++++++++-------- app/views/packages/notfound.slim | 2 +- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 88e15e5..d3afe5d 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -19,16 +19,17 @@ class PackagesController < ApplicationController # TODO: Get only screenshots visible to the user (admin or owner or approved) @package = Package.find_by(name: params[:name]) - unless @package + if @package.nil? @packagename = params[:name] - render 'notfound' - end + render 'notfound', status: 404 + else - # The first page of screenshots (if there are multiple at all) shows the - # first image twice as large. So the first page contains 5 images while - # the second and further page contain 6 images. - @page = params[:page] - @screenshots = screenshots_visible_to_user(@package).paginate(page: @page, per_page: 6) + # The first page of screenshots (if there are multiple at all) shows the + # first image twice as large. So the first page contains 5 images while + # the second and further page contain 6 images. + @page = params[:page] + @screenshots = screenshots_visible_to_user(@package).paginate(page: @page, per_page: 6) + end end # Show upload form for new images diff --git a/app/views/packages/notfound.slim b/app/views/packages/notfound.slim index 9f0dcd2..7d9db79 100644 --- a/app/views/packages/notfound.slim +++ b/app/views/packages/notfound.slim @@ -4,7 +4,7 @@ h1 p ' I'm afraid but there is no package - em =@package_name + em =>@packagename ' in the database. It may be that a package that is available ' in your favorite Linux distribution is not listed here. ' If you think this is an error then feel free to leave