title: rails console rollback on save
body: <p>I am a new to rails. I am working with rails 4.2 and I broke something in my user.rb model or controller so that I can't use save or update in console or in in the web browser(for some varibles in user, I can change the name, email, and password in the browser). I found a similar problem <a href="https://stackoverflow.com/questions/19037733/why-does-my-rails-rollback-when-i-try-to-user-save">here</a> but I couldn't get there advice to work.</p>
  
  <p>Here is my code
  User db table</p>
  
  <pre><code>create_table "users", force: :cascade do |t|
    t.string   "name"
    t.string   "email"
    t.datetime "created_at",                          null: false
    t.datetime "updated_at",                          null: false
    t.string   "avatar_file_name"
    t.string   "avatar_content_type"
    t.integer  "avatar_file_size"
    t.datetime "avatar_updated_at"
    t.string   "password_hash"
    t.string   "password_salt"
    t.boolean  "admin",               default: false
  end
  </code></pre>
  
  <p>User.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
      has_many :recipes
      has_many :comments
  
      #attr_accessible :email, :password, :password_confirmation
      attr_accessor :password
  
      before_save :encrypt_password
  
      validates_confirmation_of :password, :on =&gt; :create
      #validates :name, presence: true, uniqueness: true
      #validates :email, presence: true, uniqueness: true
      validates :password, presence: true, length: { in: 6..20 }
  
  
        has_attached_file :avatar, :styles =&gt; {
          :medium =&gt; "300x300&gt;",
          :thumb =&gt; "100x100&gt;"
        },
        :default_url =&gt; "/images/:style/missing.png",
        :bucket =&gt;'davisrecipebook',
        :storage =&gt; :s3,
        :s3_credentials =&gt; "#{Rails.root}/config/s3.yml"
        #:s3_credentials =&gt; Proc.new{|a| a.instance.s3_credentials }
        #:storage =&gt; :dropbox,
        #:dropbox_credentials =&gt; Rails.root.join("config/dropbox.yml")
  
      #def s3_credentials
      #  {:bucket =&gt;'davisrecipebook', :access_key_id =&gt; '', :secret_access_key =&gt; ''}
      #end
  
  
      validates_attachment_content_type :avatar, :content_type =&gt; /\Aimage\/.*\Z/
      validates_attachment_size :avatar, :less_than =&gt; 10.megabytes
  
      def self.authenticate(email, password)
          user = find_by_email(email)
          if user &amp;&amp; user.password_hash == BCrypt::Engine.hash_secret(password, user.password_salt)
              user
          else
              nil
          end
      end
  
      def encrypt_password
          if password.present?
              self.password_salt = BCrypt::Engine.generate_salt
              self.password_hash = BCrypt::Engine.hash_secret(password, password_salt)
          end
      end
  end
  </code></pre>
  
  <p>console out</p>
  
  <pre><code>2.1.5 :073 &gt; User.last
    User Load (0.5ms)  SELECT  "users".* FROM "users"  ORDER BY "users"."id" DESC LIMIT 1
   =&gt; #&lt;User id: 7, name: "hate", email: "death", created_at: "2014-12-28 07:32:22", updated_at: "2014-12-28 08:24:01", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil, password_hash: "$2a$10$9rEtvSoO0DOzm5u/Vop0O.5matAM8gTI0t6QZ470UyF...", password_salt: "$2a$10$9rEtvSoO0DOzm5u/Vop0O.", admin: false&gt; 
  2.1.5 :074 &gt; s = _
   =&gt; #&lt;User id: 7, name: "hate", email: "death", created_at: "2014-12-28 07:32:22", updated_at: "2014-12-28 08:24:01", avatar_file_name: nil, avatar_content_type: nil, avatar_file_size: nil, avatar_updated_at: nil, password_hash: "$2a$10$9rEtvSoO0DOzm5u/Vop0O.5matAM8gTI0t6QZ470UyF...", password_salt: "$2a$10$9rEtvSoO0DOzm5u/Vop0O.", admin: false&gt; 
  2.1.5 :075 &gt; s.admin = true
   =&gt; true 
  2.1.5 :076 &gt; s.save
     (0.2ms)  BEGIN
    User Exists (0.6ms)  SELECT  1 AS one FROM "users" WHERE ("users"."name" = 'hate' AND "users"."id" != 7) LIMIT 1
    User Exists (0.3ms)  SELECT  1 AS one FROM "users" WHERE ("users"."email" = 'death' AND "users"."id" != 7) LIMIT 1
     (0.2ms)  ROLLBACK
   =&gt; false 
  2.1.5 :077 &gt; s.errors
  
  @messages={:password=&gt;["can't be blank", "can't be blank", "is too short (minimum is 6 characters)"]}&gt;
  </code></pre>