Ruby on Rails - User not being entered into database -
i have set users model in ror, , running trouble when trying enter in new user in rails console. here command , output get:
[1] pry(main)> user.create(name: "michael hartl", email: "mhartl@example.com", password: "foobar", password_confirmation: "foobar") (0.1ms) begin user exists (0.2ms) select 1 one `users` `users`.`email` = 'mhartl@example.com' limit 1 sql (0.2ms) insert `users` (`created_at`, `updated_at`) values ('2014-08-18 22:53:03', '2014-08-18 22:53:03') (0.3ms) commit => #<user id: 4, name: nil, email: nil, created_at: "2014-08-18 22:53:03", updated_at: "2014-08-18 22:53:03", password_digest: nil> it saying user exists (when doesn't already). have idea what's going on? thanks.
edit:
user.all gives:
=> [#<user id: 1, name: "bob jones", email: "jones@gmail.com", created_at: "2014-08-07 00:14:34", updated_at: "2014-08-07 00:14:34", password_digest: nil>, #<user id: 2, name: nil, email: nil, created_at: "2014-08-18 22:44:58", updated_at: "2014-08-18 22:44:58", password_digest: nil>, #<user id: 3, name: nil, email: nil, created_at: "2014-08-18 22:47:07", updated_at: "2014-08-18 22:47:07", password_digest: nil>, #<user id: 4, name: nil, email: nil, created_at: "2014-08-18 22:53:03", updated_at: "2014-08-18 22:53:03", password_digest: nil>] the bob jones user created before happened.
edit 2:
user model (user.rb) looks this:
class user < activerecord::base attr_accessor :name, :email, :password_digest before_save { self.email = email.downcase } validates :name, presence: true, length: { maximum: 50 } valid_email_regex = /\a[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i validates :email, presence: true, format: { with: valid_email_regex }, uniqueness: { case_sensitive: false } has_secure_password validates :password, length: { minimum: 6 } has_many :microposts end migrations:
class createusers < activerecord::migration def change create_table :users |t| t.string :name t.string :email t.string :password_digest t.timestamps end end end class addindextousersemail < activerecord::migration def change add_index :users, :email, unique: true end end class addpassworddigesttousers < activerecord::migration def change add_column :users, :password_digest, :string end end edit 3:
output using errors.full_messages (no message shows up), still doesn't put user in (only new entry null values)
pry(main)> user.create(name: "michael hartl", email: "mhartl@example.com", password: "foobar", password_confirmation: "foobar").errors.full_messages (0.2ms) begin user exists (0.2ms) select 1 one `users` `users`.`email` = 'mhartl@example.com' limit 1 sql (0.2ms) insert `users` (`created_at`, `updated_at`) values ('2014-08-19 00:33:40', '2014-08-19 00:33:40') (0.9ms) commit => []
i had similar problem, try deleting name , email attr_accessor in user model
Comments
Post a Comment