Handle attempts to agree terms by users with validation errors better
authorTom Hughes <tom@compton.nu>
Tue, 12 Oct 2010 19:34:49 +0000 (20:34 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 12 Oct 2010 19:34:49 +0000 (20:34 +0100)
app/controllers/user_controller.rb

index e5a2f04bd1792149c1423e01d1c8fc1b3001ad06..c8603afec560666d3dd54514b984f32452f96d28 100644 (file)
@@ -32,7 +32,12 @@ class UserController < ApplicationController
 
       if @user
         if @user.invalid?
-          render :action => :new
+          if @user.new_record?
+            render :action => :new
+          else
+            flash[:errors] = @user.errors
+            redirect_to :action => :account, :display_name => @user.display_name
+          end
         elsif @user.terms_agreed?
           redirect_to :action => :account, :display_name => @user.display_name
         end
@@ -123,7 +128,7 @@ class UserController < ApplicationController
     else
       if flash[:errors]
         flash[:errors].each do |attr,msg|
-          attr = "new_email" if attr == "email"
+          attr = "new_email" if attr == "email" and !@user.new_email.nil?
           @user.errors.add(attr,msg)
         end
       end