質問編集履歴

3

訂正文追加

2017/01/27 02:09

投稿

mogemoge
mogemoge

スコア12

test CHANGED
File without changes
test CHANGED
@@ -54,6 +54,12 @@
54
54
 
55
55
 
56
56
 
57
+ ###訂正
58
+
59
+ 表示されるのは$〜ではなく、#{j(render partial:'partial1')}でした。
60
+
61
+
62
+
57
63
  ###補足情報(言語/FW/ツール等のバージョンなど)
58
64
 
59
65
  ubuntu 15.04 / Rails 5.0.0.1

2

ソースコード追加

2017/01/27 02:09

投稿

mogemoge
mogemoge

スコア12

test CHANGED
File without changes
test CHANGED
@@ -399,3 +399,13 @@
399
399
  end
400
400
 
401
401
  ```
402
+
403
+
404
+
405
+ show.html.erbのボタンは実際には以下です。
406
+
407
+ ```ここに言語を入力
408
+
409
+ <%= button_to '1. '+@qdata[0],button_path(qid:@question.qid,chosen:@qdata[0],answer:@qdata[4]),method: :get,remote:true,id:1,style:"height:30px" %>
410
+
411
+ ```

1

ソースコード追加

2017/01/27 02:03

投稿

mogemoge
mogemoge

スコア12

test CHANGED
File without changes
test CHANGED
@@ -61,3 +61,341 @@
61
61
 
62
62
 
63
63
  Railsを始めたばかりなのでどこか勘違いしているのだと思います。よろしくお願いします。
64
+
65
+
66
+
67
+ ###追記
68
+
69
+ 情報を追加します。
70
+
71
+
72
+
73
+ Gemfile
74
+
75
+ ```ここに言語を入力
76
+
77
+ source 'https://rubygems.org'
78
+
79
+
80
+
81
+
82
+
83
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
84
+
85
+ gem 'rails', '~> 5.0.0'
86
+
87
+ # Use sqlite3 as the database for Active Record
88
+
89
+ gem 'sqlite3'
90
+
91
+ gem 'jquery-rails'
92
+
93
+ # Use Puma as the app server
94
+
95
+ gem 'puma', '~> 3.0'
96
+
97
+ # Use SCSS for stylesheets
98
+
99
+ gem 'sass-rails', '~> 5.0'
100
+
101
+ # Use Uglifier as compressor for JavaScript assets
102
+
103
+ gem 'uglifier', '>= 1.3.0'
104
+
105
+ # Use CoffeeScript for .coffee assets and views
106
+
107
+ gem 'coffee-rails', '~> 4.2'
108
+
109
+ # See https://github.com/rails/execjs#readme for more supported runtimes
110
+
111
+ # gem 'therubyracer', platforms: :ruby
112
+
113
+
114
+
115
+ # Use jquery as the JavaScript library
116
+
117
+ gem 'jquery-rails'
118
+
119
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
120
+
121
+ gem 'turbolinks', '~> 5'
122
+
123
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
124
+
125
+ gem 'jbuilder', '~> 2.5'
126
+
127
+ # Use Redis adapter to run Action Cable in production
128
+
129
+ # gem 'redis', '~> 3.0'
130
+
131
+ # Use ActiveModel has_secure_password
132
+
133
+ gem 'bcrypt', '~> 3.1.7'
134
+
135
+
136
+
137
+ # Use Capistrano for deployment
138
+
139
+ # gem 'capistrano-rails', group: :development
140
+
141
+
142
+
143
+ group :development, :test do
144
+
145
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
146
+
147
+ gem 'byebug', platform: :mri
148
+
149
+ end
150
+
151
+
152
+
153
+ group :development do
154
+
155
+ # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
156
+
157
+ gem 'web-console'
158
+
159
+ gem 'listen', '~> 3.0.5'
160
+
161
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
162
+
163
+ gem 'spring'
164
+
165
+ gem 'spring-watcher-listen', '~> 2.0.0'
166
+
167
+ end
168
+
169
+
170
+
171
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
172
+
173
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
174
+
175
+ ```
176
+
177
+
178
+
179
+ questions_controller.rb
180
+
181
+ ```Ruby
182
+
183
+ class QuestionsController < ApplicationController
184
+
185
+
186
+
187
+ include AjaxHelper
188
+
189
+
190
+
191
+ @@answered=false
192
+
193
+ @@reload_status='next'
194
+
195
+ @@question_set=Question.new
196
+
197
+
198
+
199
+ def index
200
+
201
+ end
202
+
203
+
204
+
205
+ def show
206
+
207
+ @@answered=false
208
+
209
+ @@questions=Question.all
210
+
211
+ @num_of_questions=@@questions.length
212
+
213
+
214
+
215
+ @@users=User.where(exist: true)
216
+
217
+
218
+
219
+ #@question_set||=@@questions.sample
220
+
221
+ if @@reload_status=='next'
222
+
223
+ margin_max=Float::MAX
224
+
225
+ @@questions.each do |q|
226
+
227
+ if (current_user.theta-q.b).abs<margin_max
228
+
229
+ @margin_max=(current_user.theta-q.b).abs
230
+
231
+ @@question_set=q
232
+
233
+ end
234
+
235
+ end
236
+
237
+ @question=@@question_set
238
+
239
+ else
240
+
241
+ @question=@@questions.sample
242
+
243
+ end
244
+
245
+
246
+
247
+ collects=0
248
+
249
+ @@questions.each do |q|
250
+
251
+ collects+=eval("q.user#{current_user.number}")
252
+
253
+ end
254
+
255
+ @accuracy=collects/@@questions.length.to_f
256
+
257
+ end
258
+
259
+
260
+
261
+ def ajax_method
262
+
263
+ if params['reload'].present?
264
+
265
+ @@reload_status=params['reload']
266
+
267
+ end
268
+
269
+ respond_to do |format|
270
+
271
+ format.js{render ajax_redirect_to "http://localhost:3000/questions/show"}
272
+
273
+ end
274
+
275
+ end
276
+
277
+
278
+
279
+ def button
280
+
281
+ if params['chosen'].present?&&!@@answered
282
+
283
+ if params['chosen']==params['answer']
284
+
285
+ @result=1
286
+
287
+ else
288
+
289
+ @result=0
290
+
291
+ end
292
+
293
+ @@question_set.update("user#{current_user.number}": @result)
294
+
295
+ @@answered=true
296
+
297
+ current_user.exist=true
298
+
299
+ current_user.save
300
+
301
+
302
+
303
+ l_theta=Float::MIN
304
+
305
+ -3.0.step(3.0,0.1) do |theta_arg|
306
+
307
+ tmp_calc=1.0
308
+
309
+ @@questions.each do |q|
310
+
311
+ tmp_calc*=(1.0/(1.0+Math.exp(-1.7*(theta_arg-q.b))))**eval("q.user#{current_user.number}")*(1.0-1.0/(1.0+Math.exp(-1.7*(theta_arg-q.b))))**(1.0-eval("q.user#{current_user.number}"))
312
+
313
+ end
314
+
315
+ if l_theta<tmp_calc
316
+
317
+ current_user.theta=theta_arg
318
+
319
+ l_theta=tmp_calc
320
+
321
+ end
322
+
323
+ end
324
+
325
+ current_user.save
326
+
327
+ p "updated theta of user#{current_user.number}: "+current_user.theta.to_s
328
+
329
+ l_b=Float::MIN
330
+
331
+ -3.0.step(3.0,0.1) do |b_arg|
332
+
333
+ tmp_calc=1.0
334
+
335
+ @@users.each do |u|
336
+
337
+ tmp_calc*=(1.0/(1.0+Math.exp(-1.7*(u.theta-b_arg))))**eval("@@question_set.user#{u.number}")*(1.0-1.0/(1.0+Math.exp(-1.7*(u.theta-b_arg))))**(1.0-eval("@@question_set.user#{u.number}"))
338
+
339
+ end
340
+
341
+ if l_b<tmp_calc
342
+
343
+ @@question_set.b=b_arg
344
+
345
+ l_b=tmp_calc
346
+
347
+ end
348
+
349
+ end
350
+
351
+ @@question_set.save
352
+
353
+ p "updated b of questions#{@@question_set.qid}: "+@@question_set.b.to_s
354
+
355
+
356
+
357
+ f=File.open('./db/record.txt', 'w')
358
+
359
+ record=""
360
+
361
+ @@users.each do |u|
362
+
363
+ @@questions.each do |q|
364
+
365
+ record+="u_"+u.number.to_s+"_"+q.qid.to_s+"="+eval("q.user#{u.number}").to_s+";"
366
+
367
+ end
368
+
369
+ end
370
+
371
+ f.print encrypt(record)
372
+
373
+ f.close
374
+
375
+ end
376
+
377
+ end
378
+
379
+
380
+
381
+ def encrypt(word)
382
+
383
+ crypt = ActiveSupport::MessageEncryptor.new(SECURE, CIPHER)
384
+
385
+ crypt.encrypt_and_sign(word)
386
+
387
+ end
388
+
389
+
390
+
391
+ def decrypt(word)
392
+
393
+ crypt = ActiveSupport::MessageEncryptor.new(SECURE, CIPHER)
394
+
395
+ crypt.decrypt_and_verify(word)
396
+
397
+ end
398
+
399
+ end
400
+
401
+ ```