Report a friendly error for attempts to reference a user that does
authorTom Hughes <tom@compton.nu>
Sun, 27 Apr 2008 12:21:32 +0000 (12:21 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 27 Apr 2008 12:21:32 +0000 (12:21 +0000)
not exist. Closes #805.

app/controllers/diary_entry_controller.rb
app/controllers/user_controller.rb
app/views/diary_entry/no_such_user.rhtml [new file with mode: 0644]
app/views/user/no_such_user.rhtml [new file with mode: 0644]

index 643728dc44a7408efb52944d03d4441947f0ec41..a3b37b931beabf3c7cd9fcbca435d62c41c37914 100644 (file)
@@ -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,
index bd0c143c0ce7f5866bb35c9668e09b3485633263..5d113910d86916f10b44e2b7e33111e7672b9241 100644 (file)
@@ -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 (file)
index 0000000..7820b48
--- /dev/null
@@ -0,0 +1,2 @@
+<h2><%= h(@not_found_user) %></h2>
+<p>Sorry, there is no user with the name <%= @not_found_user -%>. Please check your spelling, or maybe the link you clicked is wrong.</p>
diff --git a/app/views/user/no_such_user.rhtml b/app/views/user/no_such_user.rhtml
new file mode 100644 (file)
index 0000000..7820b48
--- /dev/null
@@ -0,0 +1,2 @@
+<h2><%= h(@not_found_user) %></h2>
+<p>Sorry, there is no user with the name <%= @not_found_user -%>. Please check your spelling, or maybe the link you clicked is wrong.</p>