質問編集履歴
7
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -110,7 +110,7 @@
|
|
110
110
|
```
|
111
111
|
|
112
112
|
### エラーのでるソースコード
|
113
|
-
home.html.erb
|
113
|
+
/sample_app/app/views/static_pages/home.html.erb
|
114
114
|
```ここに言語名を入力
|
115
115
|
<% if logged_in? %>
|
116
116
|
<%= render 'user_logged_in' %>
|
6
改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -118,7 +118,7 @@
|
|
118
118
|
<%= render 'user_not_logged_in' %>
|
119
119
|
<% end %>
|
120
120
|
```
|
121
|
-
_user_logged_in.html.erb
|
121
|
+
/sample_app/app/views/static_pages/_user_logged_in.html.erb
|
122
122
|
```
|
123
123
|
<div class="row">
|
124
124
|
<aside class="col-md-4">
|
@@ -135,7 +135,7 @@
|
|
135
135
|
</div>
|
136
136
|
</div>
|
137
137
|
```
|
138
|
-
_user_not_logged_in.html.erb
|
138
|
+
/sample_app/app/views/static_pages/_user_not_logged_in.html.erb
|
139
139
|
```
|
140
140
|
<div class="center jumbotron">
|
141
141
|
<h1>Welcome to the Sample App</h1>
|
@@ -150,7 +150,7 @@
|
|
150
150
|
</div>
|
151
151
|
```
|
152
152
|
###エラーのでないソースコード
|
153
|
-
home.html.erb
|
153
|
+
/sample_app/app/views/static_pages/home.html.erb
|
154
154
|
```
|
155
155
|
<% if logged_in? %>
|
156
156
|
<div class="row">
|
5
改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
test/integration/microposts_interface_test.rb:15:in `block (2 levels) in <class:MicropostsInterfaceTest>'
|
18
18
|
test/integration/microposts_interface_test.rb:14:in `block in <class:MicropostsInterfaceTest>'
|
19
19
|
```
|
20
|
-
###他コード
|
20
|
+
###他参考コード
|
21
21
|
micropost_controller.rb
|
22
22
|
```class MicropostsController < ApplicationController
|
23
23
|
before_action :logged_in_user, only: [:create, :destroy]
|
@@ -78,6 +78,36 @@
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
```
|
81
|
+
_user_info.html.erb
|
82
|
+
```
|
83
|
+
<%= link_to gravatar_for(current_user, size: 50), current_user %>
|
84
|
+
<h1><%= current_user.name %></h1>
|
85
|
+
<span><%= link_to "view my profile", current_user %></span>
|
86
|
+
<span><%= pluralize(current_user.microposts.count, "micropost") %></span>
|
87
|
+
```
|
88
|
+
_micropost_form.html.erb
|
89
|
+
```
|
90
|
+
<%= form_with(model: @micropost, local: true) do |f| %>
|
91
|
+
<%= render 'shared/error_messages', object: f.object %>
|
92
|
+
<div class="field">
|
93
|
+
<%= f.text_area :content, placeholder: "Compose new micropost..." %>
|
94
|
+
</div>
|
95
|
+
<%= f.submit "Post", class: "btn btn-primary" %>
|
96
|
+
<span class="image">
|
97
|
+
<%= f.file_field :image %>
|
98
|
+
</span>
|
99
|
+
<% end %>
|
100
|
+
```
|
101
|
+
_feed.html.erb
|
102
|
+
```
|
103
|
+
<% if @feed_items.any? %>
|
104
|
+
<ol class="microposts">
|
105
|
+
<%= render @feed_items %>
|
106
|
+
</ol>
|
107
|
+
<%= will_paginate @feed_items,
|
108
|
+
params: { controller: :static_pages, action: :home } %>
|
109
|
+
<% end %>
|
110
|
+
```
|
81
111
|
|
82
112
|
### エラーのでるソースコード
|
83
113
|
home.html.erb
|
4
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -98,9 +98,6 @@
|
|
98
98
|
<section class="micropost_form">
|
99
99
|
<%= render 'shared/micropost_form' %>
|
100
100
|
</section>
|
101
|
-
<%= link_to image_tag("izumo.jpg", alt: "Rails logo", width: "350px"),
|
102
|
-
"https://twitter.com/Izu1202D" %>
|
103
|
-
<h3>↑クリック</h3></h3>
|
104
101
|
</aside>
|
105
102
|
<div class="col-md-8">
|
106
103
|
<h3>Micropost Feed</h3>
|
@@ -121,9 +118,6 @@
|
|
121
118
|
|
122
119
|
<%= link_to "Sign up now!", signup_path, class: "btn btn-lg btn-primary" %>
|
123
120
|
</div>
|
124
|
-
|
125
|
-
<%= link_to image_tag("izumo.jpg", alt: "Rails logo", width: "500px"),
|
126
|
-
"https://twitter.com/Izu1202D" %>
|
127
121
|
```
|
128
122
|
###エラーのでないソースコード
|
129
123
|
home.html.erb
|
3
改善
title
CHANGED
File without changes
|
body
CHANGED
@@ -17,7 +17,8 @@
|
|
17
17
|
test/integration/microposts_interface_test.rb:15:in `block (2 levels) in <class:MicropostsInterfaceTest>'
|
18
18
|
test/integration/microposts_interface_test.rb:14:in `block in <class:MicropostsInterfaceTest>'
|
19
19
|
```
|
20
|
+
###他コード
|
20
|
-
|
21
|
+
micropost_controller.rb
|
21
22
|
```class MicropostsController < ApplicationController
|
22
23
|
before_action :logged_in_user, only: [:create, :destroy]
|
23
24
|
before_action :correct_user, only: :destroy
|
@@ -37,7 +38,47 @@
|
|
37
38
|
.
|
38
39
|
|
39
40
|
```
|
41
|
+
microposts_interface_test
|
42
|
+
```
|
43
|
+
require 'test_helper'
|
40
44
|
|
45
|
+
class MicropostsInterfaceTest < ActionDispatch::IntegrationTest
|
46
|
+
|
47
|
+
def setup
|
48
|
+
@user = users(:michael)
|
49
|
+
end
|
50
|
+
|
51
|
+
test "micropost interface" do
|
52
|
+
log_in_as(@user)
|
53
|
+
get root_path
|
54
|
+
assert_select 'div.pagination'
|
55
|
+
# 無効な送信
|
56
|
+
assert_no_difference 'Micropost.count' do
|
57
|
+
post microposts_path, params: { micropost: { content: "" } }
|
58
|
+
end
|
59
|
+
assert_select 'div#error_explanation'
|
60
|
+
assert_select 'a[href=?]', '/?page=2' # 正しいページネーションリンク
|
61
|
+
# 有効な送信
|
62
|
+
content = "This micropost really ties the room together"
|
63
|
+
assert_difference 'Micropost.count', 1 do
|
64
|
+
post microposts_path, params: { micropost: { content: content } }
|
65
|
+
end
|
66
|
+
assert_redirected_to root_url
|
67
|
+
follow_redirect!
|
68
|
+
assert_match content, response.body
|
69
|
+
# 投稿を削除する
|
70
|
+
assert_select 'a', text: 'delete'
|
71
|
+
first_micropost = @user.microposts.paginate(page: 1).first
|
72
|
+
assert_difference 'Micropost.count', -1 do
|
73
|
+
delete micropost_path(first_micropost)
|
74
|
+
end
|
75
|
+
# 違うユーザーのプロフィールにアクセス(削除リンクがないことを確認)
|
76
|
+
get user_path(users(:archer))
|
77
|
+
assert_select 'a', text: 'delete', count: 0
|
78
|
+
end
|
79
|
+
end
|
80
|
+
```
|
81
|
+
|
41
82
|
### エラーのでるソースコード
|
42
83
|
home.html.erb
|
43
84
|
```ここに言語名を入力
|
2
誤字
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
rails tutorial 第13章 13.3.5 リスト13,57テスト時のエラー home.html.erbでパーシャルを使用した場合
|
1
|
+
誤字rails tutorial 第13章 13.3.5 リスト13,57テスト時のエラー home.html.erbでパーシャルを使用した場合
|
body
CHANGED
@@ -17,7 +17,27 @@
|
|
17
17
|
test/integration/microposts_interface_test.rb:15:in `block (2 levels) in <class:MicropostsInterfaceTest>'
|
18
18
|
test/integration/microposts_interface_test.rb:14:in `block in <class:MicropostsInterfaceTest>'
|
19
19
|
```
|
20
|
+
###micropost_controller.rb
|
21
|
+
```class MicropostsController < ApplicationController
|
22
|
+
before_action :logged_in_user, only: [:create, :destroy]
|
23
|
+
before_action :correct_user, only: :destroy
|
20
24
|
|
25
|
+
def create
|
26
|
+
@micropost = current_user.microposts.build(micropost_params)
|
27
|
+
if @micropost.save
|
28
|
+
flash[:success] = "Micropost created!"
|
29
|
+
redirect_to root_url
|
30
|
+
else
|
31
|
+
@feed_items = current_user.feed.paginate(page: params[:page])
|
32
|
+
render 'static_pages/home'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
.
|
36
|
+
.
|
37
|
+
.
|
38
|
+
|
39
|
+
```
|
40
|
+
|
21
41
|
### エラーのでるソースコード
|
22
42
|
home.html.erb
|
23
43
|
```ここに言語名を入力
|
@@ -47,7 +67,7 @@
|
|
47
67
|
</div>
|
48
68
|
</div>
|
49
69
|
```
|
50
|
-
_user_not_logged_in.html
|
70
|
+
_user_not_logged_in.html.erb
|
51
71
|
```
|
52
72
|
<div class="center jumbotron">
|
53
73
|
<h1>Welcome to the Sample App</h1>
|
1
誤字
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,7 +19,7 @@
|
|
19
19
|
```
|
20
20
|
|
21
21
|
### エラーのでるソースコード
|
22
|
-
home.html
|
22
|
+
home.html.erb
|
23
23
|
```ここに言語名を入力
|
24
24
|
<% if logged_in? %>
|
25
25
|
<%= render 'user_logged_in' %>
|