From 97c5878227a30a722ce60b2758ff2764d14e6ef2 Mon Sep 17 00:00:00 2001 From: Christoph Haas Date: Fri, 15 Jul 2016 18:16:11 +0200 Subject: [PATCH] User-friendly 404-page added --- app/controllers/packages_controller.rb | 7 ++++++- app/views/packages/notfound.slim | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 app/views/packages/notfound.slim diff --git a/app/controllers/packages_controller.rb b/app/controllers/packages_controller.rb index 128c869..23198fb 100644 --- a/app/controllers/packages_controller.rb +++ b/app/controllers/packages_controller.rb @@ -11,7 +11,12 @@ class PackagesController < ApplicationController end def details - @package = Package.find_by!(name: params[:name]) + @package = Package.find_by(name: params[:name]) + + unless @package + @packagename = params[:name] + render 'notfound' + end end def upload diff --git a/app/views/packages/notfound.slim b/app/views/packages/notfound.slim new file mode 100644 index 0000000..e49bd3a --- /dev/null +++ b/app/views/packages/notfound.slim @@ -0,0 +1,22 @@ +.row + + h1 + i.fi-alert + ' No such package… + + p + ' I'm afraid but there is no package + em =@package_name + ' 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 + a href="mailto:email@christoph-haas.de" feedback + + p + ' Perhaps you want to search for some other piece of software? + = form_tag(packages_grid_path, method: 'GET') + div.row.collapse.postfix-round + div.small-9.columns + input type="text" name="search"autofocus="true" + div.small-3.columns + input.button.postfix type="submit" value="Search"