1. lockethebiglobe

    Posted

    lockethebiglobe
Changes in title
+Ruby on Rails チュートリアル(windows10環境)
Changes in tags
Changes in body
Source | HTML | Preview
@@ -0,0 +1,32 @@
+# Ruby on Rails チュートリアルをWindows10で動かしてみた h1
+初投稿なので書き方は徐々に覚えていくつもりです
+
+2・3・3 ユーザーはたくさんおおくのマイクロポストを持っているで
+詰まっている
+
+--------------------------------------------------------------
+irb(main):040:0> first_usr = User.first
+ User Load (0.5ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
+=> #<User id: 1, name: "MH", email: "MH@example.com", created_at: "2020-02-22 05:06:50", updated_at: "2020-02-22 05:06:50">
+irb(main):041:0> first_usr.microposts
+ Micropost Load (0.5ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? LIMIT ? [["user_id", 1], ["LIMIT", 11]]
+=> #<ActiveRecord::Associations::CollectionProxy [#<Micropost id: 1, content: "FirstPost!", user_id: 1, created_at: "2020-02-22 05:05:13", updated_at: "2020-02-22 05:05:13">, #<Micropost id: 2, content: "SecondPost", user_id: 1, created_at: "2020-02-22 05:05:40", updated_at: "2020-02-22 05:05:40">]>
+irb(main):042:0> micropost = first_user.microposts.first
+ Micropost Load (0.4ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."id" ASC LIMIT ? [["user_id", 1], ["LIMIT", 1]]
+=> #<Micropost id: 1, content: "FirstPost!", user_id: 1, created_at: "2020-02-22 05:05:13", updated_at: "2020-02-22 05:05:13">
+irb(main):043:0> micropost.user
+Traceback (most recent call last):
+ 1: from (irb):43
+NoMethodError (undefined method `user' for #<Micropost:0x00000000063c1ad0>)
+Did you mean? user_id
+irb(main):044:0> p micropost
+#<Micropost id: 1, content: "FirstPost!", user_id: 1, created_at: "2020-02-22 05:05:13", updated_at: "2020-02-22 05:05:13">
+----------------------------------------------------------
+
+Tracebackで
+micropost のdid you mean? user_id
+pメソッドで確認すると確かにmicropostの中にid やuser?id はあるがuserはないですね
+
+チュートリアルをやっているのかやらされているのかわけがわからなくなってきた
+
+次いってみよ