Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save stephepush/4b3be6a317822417cf9402d96bce4d16 to your computer and use it in GitHub Desktop.

Select an option

Save stephepush/4b3be6a317822417cf9402d96bce4d16 to your computer and use it in GitHub Desktop.
Rails Console Adding models printout
~/.../PryPress/pry-press-backend // ♥ > rails console
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Running via Spring preloader in process 50251
Loading development environment (Rails 6.0.3.2)
2.6.1 :001 > user1 = User.create(name: "William T. Riker", street_address: "745 Maple lane", zipcode: "22302", isAdmin: false)
(3.7ms) BEGIN
User Create (14.3ms) INSERT INTO "users" ("name", "street_address", "zipcode", "isAdmin", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["name", "William T. Riker"], ["street_address", "745 Maple lane"], ["zipcode", "22302"], ["isAdmin", false], ["created_at", "2020-07-08 19:57:00.031328"], ["updated_at", "2020-07-08 19:57:00.031328"]]
(32.0ms) COMMIT
=> #<User id: 1, name: "William T. Riker", street_address: "745 Maple lane", zipcode: "22302", isAdmin: false, created_at: "2020-07-08 19:57:00", updated_at: "2020-07-08 19:57:00">
2.6.1 :002 > user1
=> #<User id: 1, name: "William T. Riker", street_address: "745 Maple lane", zipcode: "22302", isAdmin: false, created_at: "2020-07-08 19:57:00", updated_at: "2020-07-08 19:57:00">
2.6.1 :003 > newspaper1 = Newspaper.create(name: "New York Times", logo: "https://howlround.com/sites/default/files/2018-11/nyt.png")
Traceback (most recent call last):
1: from (irb):3
ActiveModel::UnknownAttributeError (unknown attribute 'name' for Newspaper.)
2.6.1 :004 > newspaper1 = Newspaper.create(newspaper: "New York Times", logo: "https://howlround.com/sites/default/files/2018-11/nyt.png")
(25.1ms) BEGIN
Newspaper Create (7.5ms) INSERT INTO "newspapers" ("newspaper", "logo", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["newspaper", "New York Times"], ["logo", "https://howlround.com/sites/default/files/2018-11/nyt.png"], ["created_at", "2020-07-08 20:00:03.181436"], ["updated_at", "2020-07-08 20:00:03.181436"]]
(34.2ms) COMMIT
=> #<Newspaper id: 1, newspaper: "New York Times", logo: "https://howlround.com/sites/default/files/2018-11/...", created_at: "2020-07-08 20:00:03", updated_at: "2020-07-08 20:00:03">
2.6.1 :005 > newspaper1
=> #<Newspaper id: 1, newspaper: "New York Times", logo: "https://howlround.com/sites/default/files/2018-11/...", created_at: "2020-07-08 20:00:03", updated_at: "2020-07-08 20:00:03">
2.6.1 :006 > subscription1 = Subscription.create(user_id: user1.id, newspaper_id: newspaper1.id)
(2.1ms) BEGIN
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Newspaper Load (1.1ms) SELECT "newspapers".* FROM "newspapers" WHERE "newspapers"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Subscription Create (37.3ms) INSERT INTO "subscriptions" ("user_id", "newspaper_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["user_id", 1], ["newspaper_id", 1], ["created_at", "2020-07-08 20:02:31.063591"], ["updated_at", "2020-07-08 20:02:31.063591"]]
(4.5ms) COMMIT
=> #<Subscription id: 1, user_id: 1, newspaper_id: 1, created_at: "2020-07-08 20:02:31", updated_at: "2020-07-08 20:02:31">
2.6.1 :007 > User.all
User Load (0.9ms) SELECT "users".* FROM "users" LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<User id: 1, name: "William T. Riker", street_address: "745 Maple lane", zipcode: "22302", isAdmin: false, created_at: "2020-07-08 19:57:00", updated_at: "2020-07-08 19:57:00">]>
2.6.1 :008 > Newspaper.all
Newspaper Load (1.1ms) SELECT "newspapers".* FROM "newspapers" LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Newspaper id: 1, newspaper: "New York Times", logo: "https://howlround.com/sites/default/files/2018-11/...", created_at: "2020-07-08 20:00:03", updated_at: "2020-07-08 20:00:03">]>
2.6.1 :009 > Subscriptions.all
Traceback (most recent call last):
1: from (irb):9
NameError (uninitialized constant Subscriptions)
2.6.1 :010 > Subscription.all
Subscription Load (0.6ms) SELECT "subscriptions".* FROM "subscriptions" LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Subscription id: 1, user_id: 1, newspaper_id: 1, created_at: "2020-07-08 20:02:31", updated_at: "2020-07-08 20:02:31">]>
2.6.1 :011 > user2 = User.create(name: "Will Graham", street_address: "745 Main St.", zipcode: "22305", isAdmin: false)
(3.7ms) BEGIN
User Create (0.6ms) INSERT INTO "users" ("name", "street_address", "zipcode", "isAdmin", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["name", "Will Graham"], ["street_address", "745 Main St."], ["zipcode", "22305"], ["isAdmin", false], ["created_at", "2020-07-08 20:05:54.889174"], ["updated_at", "2020-07-08 20:05:54.889174"]]
(3.4ms) COMMIT
=> #<User id: 2, name: "Will Graham", street_address: "745 Main St.", zipcode: "22305", isAdmin: false, created_at: "2020-07-08 20:05:54", updated_at: "2020-07-08 20:05:54">
2.6.1 :012 > subscription2 = Subscription.create(user_id: user2.id, newspaper_id: newspaper1.id)
(12.1ms) BEGIN
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
Newspaper Load (0.4ms) SELECT "newspapers".* FROM "newspapers" WHERE "newspapers"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Subscription Create (0.4ms) INSERT INTO "subscriptions" ("user_id", "newspaper_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["user_id", 2], ["newspaper_id", 1], ["created_at", "2020-07-08 20:06:21.395757"], ["updated_at", "2020-07-08 20:06:21.395757"]]
(0.6ms) COMMIT
=> #<Subscription id: 2, user_id: 2, newspaper_id: 1, created_at: "2020-07-08 20:06:21", updated_at: "2020-07-08 20:06:21">
2.6.1 :013 > Subscription.all
Subscription Load (0.4ms) SELECT "subscriptions".* FROM "subscriptions" LIMIT $1 [["LIMIT", 11]]
=> #<ActiveRecord::Relation [#<Subscription id: 1, user_id: 1, newspaper_id: 1, created_at: "2020-07-08 20:02:31", updated_at: "2020-07-08 20:02:31">, #<Subscription id: 2, user_id: 2, newspaper_id: 1, created_at: "2020-07-08 20:06:21", updated_at: "2020-07-08 20:06:21">]>
2.6.1 :014 > Subscription.count
(8.7ms) SELECT COUNT(*) FROM "subscriptions"
=> 2
2.6.1 :015 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment