Note that there are some explanatory texts on larger screens.

plurals
  1. POcreating a user inside of rails console is not populating the necessary attributes
    primarykey
    data
    text
    <p>User Model: </p> <pre><code>class User &lt; ActiveRecord::Base before_save { self.email == email.downcase } attr_accessor :name, :email validates :name, presence: true 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 } end </code></pre> <p>Inside of console:</p> <pre><code>:001 &gt; User.all User Load (3.1ms) SELECT "users".* FROM "users" =&gt; #&lt;ActiveRecord::Relation []&gt; :002 &gt; User.create(name: "Ryan Waits", email: "ryan.waits@gmail.com", password: "foobar", password_confirmation: "foobar") (0.1ms) begin transaction User Exists (0.2ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('ryan.waits@gmail.com') LIMIT 1 Binary data inserted for `string` type on column `password_digest` SQL (6.8ms) INSERT INTO "users" ("created_at", "password_digest", "updated_at") VALUES (?, ?, ?) [["created_at", Sat, 02 Nov 2013 16:20:10 UTC +00:00], ["password_digest", "$2a$10$5MhI5u90tFqO3rrS58DW7eeNBdNCCveBA.IfqHp6OpwonYNaigyPO"], ["updated_at", Sat, 02 Nov 2013 16:20:10 UTC +00:00]] (1.3ms) commit transaction =&gt; #&lt;User id: 3, name: nil, email: nil, created_at: "2013-11-02 16:20:10", updated_at: "2013-11-02 16:20:10", password_digest: "$2a$10$5MhI5u90tFqO3rrS58DW7eeNBdNCCveBA.IfqHp6Opwo..."&gt; </code></pre> <p><em>(user = User.all)</em> user.name bring back "User" and the email and password attributes bring back an undefined method error on user object.</p> <p>*Note:</p> <p>I created another user with different attributes, same result, except the name, email, attributes return nil rather than "User" and undefined method error.</p> <p>*Update:</p> <p>So I now realize that the uniqueness validation is being hit with this message:</p> <pre><code>SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('ryan.waits@gmail.com') LIMIT </code></pre> <p>But when I test a new user with new attributes, it still returns nil attributes when using the create method. However, updating the attributes like so (user.name = "adhsasd") will create a user. But then when I query User.all, the attributes are back to nil and the user is again invalid...am I hitting a different database somehow? I'm getting turned around...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload