質問編集履歴

7

エラー追加

2015/10/13 13:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -118,7 +118,7 @@
118
118
 
119
119
  logger.debug(@target2)
120
120
 
121
- @target1 = Photopost.find(session[:target1])
121
+ @target1 = Photopost.find(session[:target1]) ##Couldn't find Photopost with 'id'=
122
122
 
123
123
  @target2 = Photopost.find(session[:target2])
124
124
 

6

修正

2015/10/13 13:03

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -92,59 +92,59 @@
92
92
 
93
93
  ###追記
94
94
 
95
- tkowさんの回答を参考にphotoposts_controllerを修正したのですが、
96
95
 
97
- やはりクリックした方にしかインクリメントを与えることが出来ず、困っております。
98
96
 
99
97
  ```
100
98
 
101
- ##修正
99
+ ##修正 10/13
102
100
 
103
101
  photoposts_controller.rb
104
102
 
103
+ def index
104
+
105
+ @photoposts = Photopost.find(Photopost.pluck(:id).shuffle[0..1])
106
+
107
+ end
108
+
109
+
110
+
105
111
  def vote
106
112
 
107
- session[:target1] = params[:id]
113
+ @temp = params[:id]
108
114
 
109
- session[:target2] = params[:id]
115
+ logger.debug(@temp)
110
116
 
111
- @photopost = Photopost.find(params[:id])
117
+ logger.debug(@target1)
118
+
119
+ logger.debug(@target2)
112
120
 
113
121
  @target1 = Photopost.find(session[:target1])
114
122
 
115
123
  @target2 = Photopost.find(session[:target2])
116
124
 
117
- if @photopost == @target1
125
+ if session[:target1] == params[:id]
118
126
 
119
- @photopost.score += 1
127
+ @target1.score += 1
120
128
 
121
- @photopost.save
129
+ @target1.save
122
130
 
123
- redirect_to root_url
131
+ @target2.score -= 1
124
132
 
125
- elsif @photopost == @target2
126
-
127
- @photopost.score += 1
128
-
129
- @photopost.save
133
+ @target2.save
130
-
131
- redirect_to root_url
132
-
133
- elsif @photopost != @target1
134
-
135
- @photopost.score -= 1
136
-
137
- @photopost.save
138
134
 
139
135
  redirect_to root_url
140
136
 
141
- elsif @photopost != @target2
137
+ elsif session[:target2] == params[:id]
142
138
 
143
- @photopost.score -= 1
139
+ @target1.score -= 1
144
140
 
145
- @photopost.save
141
+ @target1.save
146
142
 
143
+ @target2.score += 1
144
+
145
+ @target2.save
146
+
147
- redirect_to root_url
147
+ redirect_to root_url
148
148
 
149
149
  end
150
150
 
@@ -152,6 +152,20 @@
152
152
 
153
153
  ```
154
154
 
155
- 私はどこを間違えて修正し、どこを修正出来ていないのでしょうか?
156
155
 
156
+
157
+ ```
158
+
157
- ※汚いコードですいません。。。index.html.erbは修正しておりません。
159
+ <% count = 1, @photoposts.each do |photopost| %>
160
+
161
+ <%= link_to image_tag(photopost.photo_url), root_path(:id => photopost.id), :method => "patch" %>
162
+
163
+ <%
164
+
165
+ session[('target'+count.to_s).to_sym]=photopost.id
166
+
167
+ count=2
168
+
169
+ end%>
170
+
171
+ ```

5

修正

2015/10/13 12:07

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -154,4 +154,4 @@
154
154
 
155
155
  私はどこを間違えて修正し、どこを修正出来ていないのでしょうか?
156
156
 
157
- ※汚いコードですいません。。。
157
+ ※汚いコードですいません。。。index.html.erbは修正しておりません。

4

修正

2015/10/10 14:39

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -94,7 +94,7 @@
94
94
 
95
95
  tkowさんの回答を参考にphotoposts_controllerを修正したのですが、
96
96
 
97
- Error発生し困っております。
97
+ やはりクリックした方にしかインクリメントを与えること出来ず、困っております。
98
98
 
99
99
  ```
100
100
 
@@ -102,16 +102,56 @@
102
102
 
103
103
  photoposts_controller.rb
104
104
 
105
- session[:target] = params[:id]
105
+ def vote
106
106
 
107
- @photopost = Photopost.find(params[:id])
107
+ session[:target1] = params[:id]
108
108
 
109
- @target1 = Photopost.find(session[:target1])
109
+ session[:target2] = params[:id]
110
110
 
111
+ @photopost = Photopost.find(params[:id])
112
+
113
+ @target1 = Photopost.find(session[:target1])
114
+
111
- @target2 = Photopost.find(session[:target2])
115
+ @target2 = Photopost.find(session[:target2])
116
+
117
+ if @photopost == @target1
118
+
119
+ @photopost.score += 1
120
+
121
+ @photopost.save
122
+
123
+ redirect_to root_url
124
+
125
+ elsif @photopost == @target2
126
+
127
+ @photopost.score += 1
128
+
129
+ @photopost.save
130
+
131
+ redirect_to root_url
132
+
133
+ elsif @photopost != @target1
134
+
135
+ @photopost.score -= 1
136
+
137
+ @photopost.save
138
+
139
+ redirect_to root_url
140
+
141
+ elsif @photopost != @target2
142
+
143
+ @photopost.score -= 1
144
+
145
+ @photopost.save
146
+
147
+ redirect_to root_url
148
+
149
+ end
150
+
151
+ end
112
152
 
113
153
  ```
114
154
 
115
- Couldn't find Photopost with 'id'=が発生してしまいます。
155
+ 私はどこを間違えて修正、どこを修正出来いないのでょうか?
116
156
 
117
- 私はどこを間違えて修正し、どこを修正出来てのでしょうか?
157
+ ※汚コードですません。。。

3

訂正

2015/10/10 11:47

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -92,19 +92,9 @@
92
92
 
93
93
  ###追記
94
94
 
95
- tkowさんの回答を参考にindex.html.erbを修正したのですが、
95
+ tkowさんの回答を参考にphotoposts_controllerを修正したのですが、
96
96
 
97
97
  Errorが発生し困っております。
98
-
99
- ```
100
-
101
- index.html.erb
102
-
103
- ##修正
104
-
105
- <%= link_to image_tag(photopost.photo_url), root_path(:id => photopost.id, :key => photopost.id), :method => "patch" %>
106
-
107
- ```
108
98
 
109
99
  ```
110
100
 
@@ -112,7 +102,7 @@
112
102
 
113
103
  photoposts_controller.rb
114
104
 
115
- session[:key] = 'id'
105
+ session[:target] = params[:id]
116
106
 
117
107
  @photopost = Photopost.find(params[:id])
118
108
 
@@ -124,4 +114,4 @@
124
114
 
125
115
  Couldn't find Photopost with 'id'=が発生してしまいます。
126
116
 
127
- 私はどこを間違えて修正してしまったのでしょうか?
117
+ 私はどこを間違えて修正し、どこを修正出来いないのでしょうか?

2

修正、エラー発生

2015/10/10 08:53

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  クリックしなかった画像の"score"カラムの数値を-=1させたいです。
8
8
 
9
- ###発生している問題・エラーメッセージ
9
+ ###発生している問題
10
10
 
11
11
  クリックした方に+=1をさせることは出来ましたが、
12
12
 
@@ -87,3 +87,41 @@
87
87
  ```
88
88
 
89
89
  ご教授のほど宜しくお願い致します。
90
+
91
+
92
+
93
+ ###追記
94
+
95
+ tkowさんの回答を参考にindex.html.erbを修正したのですが、
96
+
97
+ Errorが発生し困っております。
98
+
99
+ ```
100
+
101
+ index.html.erb
102
+
103
+ ##修正
104
+
105
+ <%= link_to image_tag(photopost.photo_url), root_path(:id => photopost.id, :key => photopost.id), :method => "patch" %>
106
+
107
+ ```
108
+
109
+ ```
110
+
111
+ ##修正
112
+
113
+ photoposts_controller.rb
114
+
115
+ session[:key] = 'id'
116
+
117
+ @photopost = Photopost.find(params[:id])
118
+
119
+ @target1 = Photopost.find(session[:target1])
120
+
121
+ @target2 = Photopost.find(session[:target2])
122
+
123
+ ```
124
+
125
+ Couldn't find Photopost with 'id'=が発生してしまいます。
126
+
127
+ 私はどこを間違えて修正してしまったのでしょうか?

1

2015/10/10 07:32

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -40,6 +40,8 @@
40
40
 
41
41
  ```
42
42
 
43
+
44
+
43
45
  ```
44
46
 
45
47
  routes.rb
@@ -49,6 +51,8 @@
49
51
  match '/', to: 'photoposts#vote', via: 'patch'
50
52
 
51
53
  ```
54
+
55
+
52
56
 
53
57
  ```
54
58
 
@@ -61,6 +65,8 @@
61
65
  <% end %>
62
66
 
63
67
  ```
68
+
69
+
64
70
 
65
71
  ```
66
72