My code:
class TestController < ApplicationController
def testpage
user = User.new(:email => '[email protected]', :encrypted_password => 'test')
user.save
end
end
I am trying to save a user manually from inside the script, but it never saves, however I am able to update the user by following code:
class TestController < ApplicationController
def testpage
user=User.find(2)
user.update(:email => 'new', :encrypted_password => 'new')
end
end
So my second code is working fine, but not first, I don't know why.
Here is my User model:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
belongs_to :manager
end
I have no idea what is wrong, I want to save users. I am using devise. And I am not getting any kind of errors as well.
edit1: On replacing user.save with user.save! I am getting this error.
Validation failed: Password can't be blank, Password confirmation doesn't match Password
User.new(email: '[email protected]', password: 'test', password_confirmation: 'test'). This should work. - Deepeshuser.savewithuser.save!and see what is the error. - DeepeshUser.create!(email: '[email protected]', password: 'test', password_confirmation: 'test')- Prashant4224