diff --git a/app/controllers/fedorarpms_controller.rb b/app/controllers/fedorarpms_controller.rb index 2ff5392..67d26e3 100644 --- a/app/controllers/fedorarpms_controller.rb +++ b/app/controllers/fedorarpms_controller.rb @@ -9,12 +9,21 @@ def index def show @name = params[:id] - @rpm = FedoraRpm.find_by_name(@name, :include => :rpm_comments) + @rpm = FedoraRpm.find_by_name!(@name, :include => :rpm_comments) @page_title = @rpm.name @dependencies = @rpm.dependency_packages @dependents = @rpm.dependent_packages + #We can register a global error handler inside the application controller for this. + rescue ActiveRecord::RecordNotFound + redirect_to :action => 'not_found' + end + def not_found + @rpm = params[:id] + @results = FedoraRpm.where('name LIKE ?', "%#{@rpm}%") + end + def full_deps @name = params[:id] @rpm = FedoraRpm.find_by_name(@name) diff --git a/app/views/fedorarpms/not_found.html.haml b/app/views/fedorarpms/not_found.html.haml new file mode 100644 index 0000000..7494b09 --- /dev/null +++ b/app/views/fedorarpms/not_found.html.haml @@ -0,0 +1,18 @@ +%h1 RPM Not Found + +Sorry, we couldn't find +%b=@rpm +as a Fedora RPM; please check your URL and try again. +%br/ +%br/ +- if @results != [] + + %table.table.table-striped.table-condensed + %thead + %tr + %th Did you mean: + + %tbody + - @results.each do |r| + %tr + %td= link_to r.rpm_name, fedorarpm_path(r.rpm_name) diff --git a/config/routes.rb b/config/routes.rb index d1f8bc2..78d7e7b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ get :full_dependents, :on => :member get :by_owner, :on => :member get :badge, :on => :member + get :not_found, :on => :member end resources :rubygems, :constraints => { :id => /.*/ } resources :searches