From a1378a6bd4cdeca537856650e6ea7321ae6eca26 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 27 Apr 2008 12:21:32 +0000 Subject: [PATCH 1/1] Report a friendly error for attempts to reference a user that does not exist. Closes #805. --- app/controllers/diary_entry_controller.rb | 15 ++++++++++----- app/controllers/user_controller.rb | 3 ++- app/views/diary_entry/no_such_user.rhtml | 2 ++ app/views/user/no_such_user.rhtml | 2 ++ 4 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 app/views/diary_entry/no_such_user.rhtml create mode 100644 app/views/user/no_such_user.rhtml diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index 643728dc4..a3b37b931 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -30,11 +30,16 @@ class DiaryEntryController < ApplicationController def list if params[:display_name] @this_user = User.find_by_display_name(params[:display_name]) - @title = @this_user.display_name + "'s diary" - @entry_pages, @entries = paginate(:diary_entries, - :conditions => ['user_id = ?', @this_user.id], - :order => 'created_at DESC', - :per_page => 20) + if @this_user + @title = @this_user.display_name + "'s diary" + @entry_pages, @entries = paginate(:diary_entries, + :conditions => ['user_id = ?', @this_user.id], + :order => 'created_at DESC', + :per_page => 20) + else + @not_found_user = params[:display_name] + render :action => 'no_such_user', :status => :not_found + end else @title = "Users' diaries" @entry_pages, @entries = paginate(:diary_entries, diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index bd0c143c0..5d113910d 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -179,7 +179,8 @@ class UserController < ApplicationController if @this_user @title = @this_user.display_name else - render :nothing => true, :status => :not_found + @not_found_user = params[:display_name] + render :action => 'no_such_user', :status => :not_found end end diff --git a/app/views/diary_entry/no_such_user.rhtml b/app/views/diary_entry/no_such_user.rhtml new file mode 100644 index 000000000..7820b4847 --- /dev/null +++ b/app/views/diary_entry/no_such_user.rhtml @@ -0,0 +1,2 @@ +

<%= h(@not_found_user) %>

+

Sorry, there is no user with the name <%= @not_found_user -%>. Please check your spelling, or maybe the link you clicked is wrong.

diff --git a/app/views/user/no_such_user.rhtml b/app/views/user/no_such_user.rhtml new file mode 100644 index 000000000..7820b4847 --- /dev/null +++ b/app/views/user/no_such_user.rhtml @@ -0,0 +1,2 @@ +

<%= h(@not_found_user) %>

+

Sorry, there is no user with the name <%= @not_found_user -%>. Please check your spelling, or maybe the link you clicked is wrong.

-- 2.45.1