Closed yutokyokutyo closed 7 years ago
RailsコンソールでMicropost.newを実行し、インスタンスを変数micropostに代入してください。その後、user_idに最初のユーザーのidを、contentに "Lorem ipsum" をそれぞれ代入してみてください。この時点では、 micropostオブジェクトのマジックカラム (created_atとupdated_at) には何が入っているでしょうか? 先ほど作ったオブジェクトを使って、micropost.userを実行してみましょう。どのような結果が返ってくるでしょうか? また、micropost.user.nameを実行した場合の結果はどうなるでしょうか? 先ほど作ったmicropostオブジェクトをデータベースに保存してみましょう。この時点でもう一度マジックカラムの内容を調べてみましょう。今度はどのような値が入っているでしょうか?
OK!
13.1.1の演習これからやる感じかな? rails consoleの結果をペタッと貼ってくれると嬉しいです 😄
あ!終わりました 😆 演習の結果については見られたくないメールアドレスがある場合は書かないようにしていて、今回はちょこちょこuser情報で該当するものがあったので書かなかった感じでした!
@yutokyokutyo OK!次からはセンシティブな情報はマスキングして載せてくれると、 周りで見ている人が演習できたのか・できなかったのかが分かって良いと思いました〜
周りで見ている人が演習できたのか・できなかったのかが分かって良いと思いました〜
気づきを得ました!押忍 :star2: ☺️ 🌟
[1] pry(main)> micropost = Micropost.new
=> #<Micropost:0x007fbd5f410d10
id: nil,
content: nil,
user_id: nil,
created_at: nil,
updated_at: nil>
[2] pry(main)> micropost.user_id = 3
=> 3
[3] pry(main)> micropost.content = "Lorem ipsum"
=> "Lorem ipsum"
[4] pry(main)> micropost
=> #<Micropost:0x007fbd5f410d10
id: nil,
content: "Lorem ipsum",
user_id: 3,
created_at: nil,
updated_at: nil>
[5] pry(main)> micropost.user
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 3], ["LIMIT", 1]]
=> #<User:0x007fbd5f1bb970
id: 3,
name: "Example User",
email: "example@railstutorial.org",
created_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
updated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
password_digest: "$2a$10$dDiuDKkhNc3dTO2Wn91Z5e/wdR/g2rtMF.1wf9Rbx.ifSfg05RYLS",
remember_digest: nil,
admin: true,
activation_digest: "$2a$10$.KXMgyGoIgLoxaZ4S2vXNurrcVYnm7zqc7/113cUXuqnPRZIuJCRW",
activated: true,
activated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[6] pry(main)> micropost.user.name
=> "Example User"
[7] pry(main)> micropost.save
(0.1ms) begin transaction
SQL (1.4ms) INSERT INTO "microposts" ("content", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["content", "Lorem ipsum"], ["user_id", 3], ["created_at", 2017-05-04 07:54:48 UTC], ["updated_at", 2017-05-04 07:54:48 UTC]]
(2.2ms) commit transaction
=> true
[8] pry(main)> micropost
=> #<Micropost:0x007fbd5f410d10
id: 3,
content: "Lorem ipsum",
user_id: 3,
created_at: Thu, 04 May 2017 07:54:48 UTC +00:00,
updated_at: Thu, 04 May 2017 07:54:48 UTC +00:00>
[1] pry(main)> micropost = Micropost.new
=> #<Micropost:0x007fbd5f6189a0
id: nil,
content: nil,
user_id: nil,
created_at: nil,
updated_at: nil>
[7] pry(main)> micropost.valid?
=> false
[11] pry(main)> micropost.errors.full_messages
=> ["User must exist", "User can't be blank", "Content can't be blank"]
[12] pry(main)> micropost.content = "a" * 150
=> "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
[13] pry(main)> micropost
=> #<Micropost:0x007fbd5f6189a0
id: nil,
content:
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
user_id: nil,
created_at: nil,
updated_at: nil>
[14] pry(main)> micropost.valid?
=> false
[15] pry(main)> micropost.errors.full_messages
=> ["User must exist",
"User can't be blank",
"Content is too long (maximum is 140 characters)"]
実家に到着してしまった。次は 13.1.3 User/Micropostの関連付けから!
[4] pry(main)> user = User.third
User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? OFFSET ? [["LIMIT", 1], ["OFFSET", 2]]
=> #<User:0x007f96d1984c38
id: 3,
name: "Example User",
email: "example@railstutorial.org",
created_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
updated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
password_digest: "$2a$10$dDiuDKkhNc3dTO2Wn91Z5e/wdR/g2rtMF.1wf9Rbx.ifSfg05RYLS",
remember_digest: nil,
admin: true,
activation_digest: "$2a$10$.KXMgyGoIgLoxaZ4S2vXNurrcVYnm7zqc7/113cUXuqnPRZIuJCRW",
activated: true,
activated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[5] pry(main)> micropost = user.microposts.create(content: "Lorem ipsum")
(0.0ms) begin transaction
SQL (1.0ms) INSERT INTO "microposts" ("content", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["content", "Lorem ipsum"], ["user_id", 3], ["created_at", 2017-05-08 01:57:42 UTC], ["updated_at", 2017-05-08 01:57:42 UTC]]
(2.5ms) commit transaction
=> #<Micropost:0x007f96d03f02a0
id: 4,
content: "Lorem ipsum",
user_id: 3,
created_at: Mon, 08 May 2017 01:57:42 UTC +00:00,
updated_at: Mon, 08 May 2017 01:57:42 UTC +00:00>
[6] pry(main)> user.microposts.find(micropost.id)
Micropost Load (0.2ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? AND "microposts"."id" = ? LIMIT ? [["user_id", 3], ["id", 4], ["LIMIT", 1]]
=> #<Micropost:0x007f96d0326220
id: 4,
content: "Lorem ipsum",
user_id: 3,
created_at: Mon, 08 May 2017 01:57:42 UTC +00:00,
updated_at: Mon, 08 May 2017 01:57:42 UTC +00:00>
[7] pry(main)> user.microposts.find(micropost)
DEPRECATION WARNING: You are passing an instance of ActiveRecord::Base to `find`. Please pass the id of the object by calling `.id`. (called from <main> at (pry):7)
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? AND "microposts"."id" = ? LIMIT ? [["user_id", 3], ["id", 4], ["LIMIT", 1]]
=> #<Micropost:0x007f96cf7d63e8
id: 4,
content: "Lorem ipsum",
user_id: 3,
created_at: Mon, 08 May 2017 01:57:42 UTC +00:00,
updated_at: Mon, 08 May 2017 01:57:42 UTC +00:00>
[8] pry(main)> user == micropost.user
=> true
[9] pry(main)> user.microposts.first == micropost
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."id" ASC LIMIT ? [["user_id", 3], ["LIMIT", 1]]
=> false
[10] pry(main)> user.microposts.first
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."id" ASC LIMIT ? [["user_id", 3], ["LIMIT", 1]]
=> #<Micropost:0x007f96d02c96d8
id: 3,
content: "Lorem ipsum",
user_id: 3,
created_at: Thu, 04 May 2017 07:54:48 UTC +00:00,
updated_at: Thu, 04 May 2017 07:54:48 UTC +00:00>
[11] pry(main)> user.microposts.second
Micropost Load (0.2ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."id" ASC LIMIT ? OFFSET ? [["user_id", 3], ["LIMIT", 1], ["OFFSET", 1]]
=> #<Micropost:0x007f96cf6f9f38
id: 4,
content: "Lorem ipsum",
user_id: 3,
created_at: Mon, 08 May 2017 01:57:42 UTC +00:00,
updated_at: Mon, 08 May 2017 01:57:42 UTC +00:00>
[12] pry(main)> user.microposts.second == micropost
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."id" ASC LIMIT ? OFFSET ? [["user_id", 3], ["LIMIT", 1], ["OFFSET", 1]]
=> true
[1] pry(main)> Micropost.first.created_at
Micropost Load (3.3ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" DESC LIMIT ? [["LIMIT", 1]]
=> Mon, 08 May 2017 01:57:42 UTC +00:00
[2] pry(main)> Micropost.last.created_at
Micropost Load (0.4ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" ASC LIMIT ? [["LIMIT", 1]]
=> Tue, 02 May 2017 06:08:46 UTC +00:00
[4] pry(main)> Micropost.first.created_at == Micropost.last.created_at
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" DESC LIMIT ? [["LIMIT", 1]]
Micropost Load (0.2ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" ASC LIMIT ? [["LIMIT", 1]]
=> false
[6] pry(main)> Micropost.first
Micropost Load (0.2ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" DESC LIMIT ? [["LIMIT", 1]]
=> #<Micropost:0x007f96d18ab2d0
id: 4,
content: "Lorem ipsum",
user_id: 3,
created_at: Mon, 08 May 2017 01:57:42 UTC +00:00,
updated_at: Mon, 08 May 2017 01:57:42 UTC +00:00>
[7] pry(main)> Micropost.last
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" ORDER BY "microposts"."created_at" ASC LIMIT ? [["LIMIT", 1]]
=> #<Micropost:0x007f96d1842c30
id: 2,
content: "i am amam",
user_id: 1,
created_at: Tue, 02 May 2017 06:08:46 UTC +00:00,
updated_at: Tue, 02 May 2017 06:08:46 UTC +00:00>
[1] pry(main)> user = User.third
User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? OFFSET ? [["LIMIT", 1], ["OFFSET", 2]]
=> #<User:0x007f96d190a5c8
id: 3,
name: "Example User",
email: "example@railstutorial.org",
created_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
updated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
password_digest: "$2a$10$dDiuDKkhNc3dTO2Wn91Z5e/wdR/g2rtMF.1wf9Rbx.ifSfg05RYLS",
remember_digest: nil,
admin: true,
activation_digest: "$2a$10$.KXMgyGoIgLoxaZ4S2vXNurrcVYnm7zqc7/113cUXuqnPRZIuJCRW",
activated: true,
activated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[2] pry(main)> user.microposts.first
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."created_at" DESC LIMIT ? [["user_id", 3], ["LIMIT", 1]]
=> #<Micropost:0x007f96d030f138
id: 4,
content: "Lorem ipsum",
user_id: 3,
created_at: Mon, 08 May 2017 01:57:42 UTC +00:00,
updated_at: Mon, 08 May 2017 01:57:42 UTC +00:00>
[3] pry(main)> user.destroy
(0.1ms) begin transaction
Micropost Load (0.2ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."created_at" DESC [["user_id", 3]]
SQL (0.3ms) DELETE FROM "microposts" WHERE "microposts"."id" = ? [["id", 4]]
SQL (0.2ms) DELETE FROM "microposts" WHERE "microposts"."id" = ? [["id", 3]]
SQL (0.1ms) DELETE FROM "users" WHERE "users"."id" = ? [["id", 3]]
(3.2ms) commit transaction
=> #<User:0x007f96d190a5c8
id: 3,
name: "Example User",
email: "example@railstutorial.org",
created_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
updated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
password_digest: "$2a$10$dDiuDKkhNc3dTO2Wn91Z5e/wdR/g2rtMF.1wf9Rbx.ifSfg05RYLS",
remember_digest: nil,
admin: true,
activation_digest: "$2a$10$.KXMgyGoIgLoxaZ4S2vXNurrcVYnm7zqc7/113cUXuqnPRZIuJCRW",
activated: true,
activated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[4] pry(main)> user
=> #<User:0x007f96d190a5c8
id: 3,
name: "Example User",
email: "example@railstutorial.org",
created_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
updated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
password_digest: "$2a$10$dDiuDKkhNc3dTO2Wn91Z5e/wdR/g2rtMF.1wf9Rbx.ifSfg05RYLS",
remember_digest: nil,
admin: true,
activation_digest: "$2a$10$.KXMgyGoIgLoxaZ4S2vXNurrcVYnm7zqc7/113cUXuqnPRZIuJCRW",
activated: true,
activated_at: Wed, 19 Apr 2017 23:11:00 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[5] pry(main)> User.third
User Load (0.1ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? OFFSET ? [["LIMIT", 1], ["OFFSET", 2]]
=> #<User:0x007f96cf6eb618
id: 4,
name: "Mr. Thelma Lebsack",
email: "example-1@railstutorial.org",
created_at: Wed, 19 Apr 2017 23:11:01 UTC +00:00,
updated_at: Wed, 19 Apr 2017 23:11:01 UTC +00:00,
password_digest: "$2a$10$OQm9jNMsndLrGhtvhvTzTuJ2c9WqcV9Y1Q/wtz50F.ALUsrlOdxjG",
remember_digest: nil,
admin: false,
activation_digest: "$2a$10$BnEPCjlKnpBhkdHGzjbUd.5JjvyhDBbvYywmaNj079TFGm.3y4B4C",
activated: true,
activated_at: Wed, 19 Apr 2017 23:11:01 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[6] pry(main)> user.microposts
=> []
[11] pry(main)> helper.time_ago_in_words(3.weeks.ago)
=> "21 days"
[12] pry(main)> helper.time_ago_in_words(6.months.ago)
=> "6 months"
[13] pry(main)> helper.time_ago_in_words(1.year.ago)
=> "about 1 year"
[14] pry(main)> user.microposts.paginate(page: nil)
Micropost Load (0.2ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? ORDER BY "microposts"."created_at" DESC LIMIT ? OFFSET ? [["user_id", 1], ["LIMIT", 30], ["OFFSET", 0]]
=> [#<Micropost:0x007f96d0279340
id: 2,
content: "nyannyan",
user_id: 1,
created_at: Tue, 09 May 2017 02:12:00 UTC +00:00,
updated_at: Tue, 09 May 2017 02:12:00 UTC +00:00>,
#<Micropost:0x007f96d0279160
id: 1,
content: "Lorm ipsum",
user_id: 1,
created_at: Tue, 09 May 2017 02:09:07 UTC +00:00,
updated_at: Tue, 09 May 2017 02:09:07 UTC +00:00>]
[15] pry(main)> user.microposts.paginate(page: nil).class
=> Micropost::ActiveRecord_AssociationRelation
[1] pry(main)> (1..10).to_a.take(6)
=> [1, 2, 3, 4, 5, 6]
[2] pry(main)> (1..10).take(6)
=> [1, 2, 3, 4, 5, 6]
[3] pry(main)> (1..10)
=> 1..10
[4] pry(main)> Faker::Lorem.sentence(5)
]=> "Quo debitis ut aliquid laboriosam earum et architecto."
[5] pry(main)> Faker::Lorem.sentence(4)
=> "Sit et est iure."
[6] pry(main)> Faker::Lorem.sentence(3)
=> "Eos debitis consectetur aut praesentium voluptates sunt."
[7] pry(main)> Faker::Lorem.sentence(1)
=> "Minus amet qui expedita dicta."
[8] pry(main)> Faker::Lorem.sentence(5)
=> "Libero maxime quas suscipit aperiam veritatis omnis rerum accusamus."
[9] pry(main)> Faker::Name.name
=> "Estella Runolfsdottir Sr."
[10] pry(main)> Faker::PhoneNumber.phone_number
=> "290-265-9490 x5970"
[11] pry(main)> Faker::Hipster.words
=> ["organic", "master", "tattooed"]
[12] pry(main)> Faker::Hipster.words
=> ["typewriter", "tousled", "bespoke"]
[13] pry(main)> Faker::Hipster.sentence
=> "Narwhal lo-fi farm-to-table waistcoat retro freegan street artisan."
[14] pry(main)> Faker::University.name
=> "Northern McLaughlin"
[15] pry(main)> Faker::ChuckNorris.fact
=> "When Chuck Norris presses Ctrl+Alt+Delete, worldwide computer restart is initiated."
% rails t (git)-[user-microposts]
Running via Spring preloader in process 84097
Started with run options --seed 3240
ERROR["test_profile_display", UsersProfileTest, 2.840877050002746]
test_profile_display#UsersProfileTest (2.84s)
ArgumentError: ArgumentError: Expecting a selector as the first argument
test/integration/users_profile_test.rb:14:in `block in <class:UsersProfileTest>'
53/53: [=========================================================================================================] 100% Time: 00:00:04, Time: 00:00:04
Finished in 4.94399s
53 tests, 226 assertions, 0 failures, 1 errors, 0 skips
https://github.com/yutokyokutyo/rebuild_sample_app/commit/65a41e65338a7604224a39180dd58764dc3414fc
次は 13.3 マイクロポストを操作するから!
次は リスト 13.50: createアクションに空の@feed_itemsインスタンス変数を追加する
から!
13章は長いなぁ。
残斬!
13.3.4 マイクロポストを削除する
13.3.5 フィード画面のマイクロポストをテストする
13.4 マイクロポストの画像投稿
13.4.1 基本的な画像アップロード
13.4.2 画像の検証
13.4.3 画像のリサイズ
13.4.4 本番環境での画像アップロード
Started POST "/microposts" for 127.0.0.1 at 2017-05-11 14:45:45 +0900
Processing by MicropostsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"klbgPXsgnQHtsiX1Th/MlkdH5ewQ99el0KRJ/kVysa6v+RnBzXFQ5QDwcD6Ys4G/5kwxJxGcbdbLjUeElqlsLA==", "micropost"=>{"content"=>"こんにちわ世界!"}, "commit"=>"Post"}
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 101], ["LIMIT", 1]]
(0.1ms) begin transaction
SQL (0.4ms) INSERT INTO "microposts" ("content", "user_id", "created_at", "updated_at") VALUES (?, ?, ?, ?) [["content", "こんにちわ世界!"], ["user_id", 101], ["created_at", 2017-05-11 05:45:45 UTC], ["updated_at", 2017-05-11 05:45:45 UTC]]
(1.8ms) commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 11ms (ActiveRecord: 2.3ms)
[1] pry(main)> user = User.first
User Load (0.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT ? [["LIMIT", 1]]
=> #<User:0x007ff2a791b058
id: 1,
name: "Example User",
email: "example@railstutorial.org",
created_at: Tue, 09 May 2017 03:24:04 UTC +00:00,
updated_at: Tue, 09 May 2017 03:24:04 UTC +00:00,
password_digest: "$2a$10$wJNbS2QbhvQ6LjvEzHhvT./N1lRPETkXszmzc3SSvFWGtTWgN37Le",
remember_digest: nil,
admin: true,
activation_digest: "$2a$10$AOgMa3e4/vK/ehmIsNzm..ag08cwzxlagiryIQXwQGa.PgBEin/56",
activated: true,
activated_at: Tue, 09 May 2017 03:24:04 UTC +00:00,
reset_digest: nil,
reset_sent_at: nil>
[2] pry(main)> Micropost.where("user_id = ?", user.id)
Micropost Load (0.4ms) SELECT "microposts".* FROM "microposts" WHERE (user_id = 1) ORDER BY "microposts"."created_at" DESC
=> [#<Micropost:0x007ff2a78f0da8
id: 295,
content: "Voluptate sunt suscipit vel iure non aut vel.",
user_id: 1,
created_at: Tue, 09 May 2017 03:24:20 UTC +00:00,
updated_at: Tue, 09 May 2017 03:24:20 UTC +00:00>,
#<Micropost:0x007ff2a78f0c40
id: 289,
content: "Quasi dolor ea qui fugit quis quo enim voluptatibus.",
user_id: 1,
created_at: Tue, 09 May 2017 03:24:20 UTC +00:00,
updated_at: Tue, 09 May 2017 03:24:20 UTC +00:00>,
#<Micropost:0x007ff2a78f0b00
id: 283,
content: "Tempora atque occaecati enim ratione itaque mollitia.",
user_id: 1,
created_at: Tue, 09 May 2017 03:24:20 UTC +00:00,
updated_at: Tue, 09 May 2017 03:24:20 UTC +00:00>,
・
・
・
[4] pry(main)> Micropost.where("user_id = ?", user.id) == user.feed
=> true
Started DELETE "/microposts/306" for 127.0.0.1 at 2017-05-11 15:15:00 +0900
Processing by MicropostsController#destroy as HTML
Parameters: {"authenticity_token"=>"WSZYe5vg+6nCM12gVGU2gnQy8vj1LDFWy+ZDezwPAlvXWj9dxJWHNfRPQR+2dyz3nliePFbCkdmZJiDevF+Aew==", "id"=>"306"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 101], ["LIMIT", 1]]
Micropost Load (0.1ms) SELECT "microposts".* FROM "microposts" WHERE "microposts"."user_id" = ? AND "microposts"."id" = ? ORDER BY "microposts"."created_at" DESC LIMIT ? [["user_id", 101], ["id", 306], ["LIMIT", 1]]
(0.1ms) begin transaction
SQL (0.4ms) DELETE FROM "microposts" WHERE "microposts"."id" = ? [["id", 306]]
(3.2ms) commit transaction
Redirected to http://localhost:3000/
Completed 302 Found in 73ms (ActiveRecord: 5.0ms)
🙆
次回は 13.4.1 Exercises 2 から!
なるほどぉ。
uploadした画像は
public/uploads/micropost/picture/309/f8aefb198069d330925e14f45e57fa2b.png
な感じで保存されてしまうのかぁ。 gitignoreした方が良さそうだなぁ。
Maximum file size is 5MB. Please choose a smaller file.
js off 等の場合は should be less than 5MB
Rails エラーが表示される。
imagemagick が必要とのこと
% brew list | grep imagemagick (git)-[user-microposts]
imagemagick
ある!
commit done!
2017-05-13T05:54:34.148755+00:00 app[web.1]: D, [2017-05-13T05:54:34.148638 #10] DEBUG -- : [249d0b64-fd18-4c17-a8a9-f63c1bb1523e] (0.8ms) BEGIN
2017-05-13T05:54:34.153463+00:00 app[web.1]: D, [2017-05-13T05:54:34.153386 #10] DEBUG -- : [249d0b64-fd18-4c17-a8a9-f63c1bb1523e] SQL (1.5ms) INSERT INTO "microposts" ("content", "user_id", "created_at", "updated_at", "picture") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["content", "LGTM!"], ["user_id", 101], ["created_at", 2017-05-13 05:54:34 UTC], ["updated_at", 2017-05-13 05:54:34 UTC], ["picture", "steve-jobs-ok-o.gif"]]
2017-05-13T05:54:36.318444+00:00 app[web.1]: D, [2017-05-13T05:54:36.318315 #10] DEBUG -- : [249d0b64-fd18-4c17-a8a9-f63c1bb1523e] (1.5ms) COMMIT
2017-05-13T05:54:36.319266+00:00 app[web.1]: I, [2017-05-13T05:54:36.319213 #10] INFO -- : [249d0b64-fd18-4c17-a8a9-f63c1bb1523e] Redirected to https://rebuildsampleapp.herokuapp.com/
2017-05-13T05:54:36.319443+00:00 app[web.1]: I, [2017-05-13T05:54:36.319391 #10] INFO -- : [249d0b64-fd18-4c17-a8a9-f63c1bb1523e] Completed 302 Found in 2400ms (ActiveRecord: 11.8ms)
2017-05-13T05:54:36.508702+00:00 app[web.1]: I, [2017-05-13T05:54:36.508615 #10] INFO -- : [cd87f3d1-b71e-4b58-add2-367470f8be00] Started GET "/" for 126.112.54.50 at 2017-05-13 05:54:36 +0000
heroku config:set S3_REGION="Regionの名前を入力"
2017-05-13T05:48:08.927963+00:00 app[web.1]: D, [2017-05-13T05:48:08.927887 #10] DEBUG -- : [01f20921-58ff-4bb5-a659-820809b5669f] (0.8ms) BEGIN
2017-05-13T05:48:08.930673+00:00 app[web.1]: D, [2017-05-13T05:48:08.930620 #10] DEBUG -- : [01f20921-58ff-4bb5-a659-820809b5669f] SQL (1.1ms) INSERT INTO "microposts" ("content", "user_id", "created_at", "updated_at", "picture") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["content", "最高に肺!"], ["user_id", 101], ["created_at", 2017-05-13 05:48:08 UTC], ["updated_at", 2017-05-13 05:48:08 UTC], ["picture", "20100213192209.jpg"]]
2017-05-13T05:48:08.952478+00:00 app[web.1]: D, [2017-05-13T05:48:08.952405 #10] DEBUG -- : [01f20921-58ff-4bb5-a659-820809b5669f] (1.1ms) ROLLBACK
2017-05-13T05:48:08.952762+00:00 app[web.1]: I, [2017-05-13T05:48:08.952719 #10] INFO -- : [01f20921-58ff-4bb5-a659-820809b5669f] Completed 500 Internal Server Error in 58ms (ActiveRecord: 3.8ms)
2017-05-13T05:48:08.953491+00:00 app[web.1]: F, [2017-05-13T05:48:08.953447 #10] FATAL -- : [01f20921-58ff-4bb5-a659-820809b5669f]
2017-05-13T05:48:08.953534+00:00 app[web.1]: F, [2017-05-13T05:48:08.953494 #10] FATAL -- : [01f20921-58ff-4bb5-a659-820809b5669f] Excon::Error::Socket (getaddrinfo: Name or service not known (SocketError)):
完!
:1st_place_medal:
オーバービュー