title: Ruby on Rails Active Record return value when create fails?
body: <p>I am new to ruby on rails and having trouble getting this work. Basically I have a user registration page which has a password confirmation. In the User class I have the following validation: </p>
  
  <pre><code>validates :password, confirmation: true
  </code></pre>
  
  <p>And in the controller I have </p>
  
  <pre><code>def create
      vals = params[:user]
      if(User.exists(vals[:username])) 
          flash[:warning] = "#{vals[:username]} already exists! Please try a new one. "
      else
          vals[:create_date] = DateTime.current
          user = User.create(vals, :without_protection =&gt; :true)
          if user==false or user==nil or user==vals
              flash[:warning] = "#{vals[:username]} has not been registered successfully. "
          else
              flash[:notice] = "#{vals[:username]} has been registered. "
          end
      end
      redirect_to users_path
  end
  </code></pre>
  
  <p>The problem is that when the password does match the confirmation, I am still getting the notice message showing that the registration is successful. As you can see I have tried several return values for <code>create</code> but none of them seems to succeed. I am pretty sure that the validation is working because I cannot see the user that I just created if password does not match with confirmation. In addition, when I use <code>create!</code>, I can see the website crashes with the validation error. Can anyone help telling me what <code>create</code> should return when the record is not validated? </p>
  
  <p>Thanks. </p>