Reputation: 137
In Rails Console:
user = HotelUser.create(:email=>'[email protected]')
(0.0ms) BEGIN
(0.0ms) ROLLBACK
=> #<HotelUser id: nil, userName: nil, email: "[email protected]", address1: nil, address2: nil, created_at: nil, updated_at: nil, password_digest: nil>`
I am new in rails.I want to create a user in rails console.But every time i m getting Rollback.Why this is happening.
Upvotes: 0
Views: 1217
Reputation: 663
Try this: t=HotelUser.new Then, type this: t.email="[email protected]" And the last command, t.save
Hope this solves your problem. The problem with .create was that you didn't pass the other params like created date and updated date and all.
Upvotes: 0
Reputation: 649
A quick and dirty way to check is to use create!
For example:
pry(main)> User.create(:fname => "Bob")
(0.1ms) begin transaction
(0.1ms) rollback transaction
=> #<User id: nil, email: nil, encrypted_password: nil, fname: "Bob", lname: nil>
pry(main)> User.create!(:fname => "Bob")
(0.1ms) begin transaction
(0.1ms) rollback transaction
ActiveRecord::RecordInvalid: Validation failed: Email can't be blank, Password can't be blank
The difference between the bang(!) and non-bang is that create! will raise an exception.
Upvotes: 3
Reputation: 298
You can check errors by these codes in Rails console and see your User model to fix it
=> user = HotelUser.create(email: '[email protected]')
=> user.errors
Upvotes: 0