teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

3

訂正文追加

2017/01/27 02:09

投稿

mogemoge
mogemoge

スコア12

title CHANGED
File without changes
body CHANGED
@@ -26,6 +26,9 @@
26
26
  ###発生している問題・エラーメッセージ
27
27
  しかし、パーシャルは表示されず、上記コード($〜)がそのまま<div id="result"></div>の中に出てきてしまいます。(ターミナルの出力には「Rendered questions/_partial1.html.erb」と出ているのですが)
28
28
 
29
+ ###訂正
30
+ 表示されるのは$〜ではなく、#{j(render partial:'partial1')}でした。
31
+
29
32
  ###補足情報(言語/FW/ツール等のバージョンなど)
30
33
  ubuntu 15.04 / Rails 5.0.0.1
31
34
 

2

ソースコード追加

2017/01/27 02:09

投稿

mogemoge
mogemoge

スコア12

title CHANGED
File without changes
body CHANGED
@@ -198,4 +198,9 @@
198
198
  crypt.decrypt_and_verify(word)
199
199
  end
200
200
  end
201
+ ```
202
+
203
+ show.html.erbのボタンは実際には以下です。
204
+ ```ここに言語を入力
205
+ <%= 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" %>
201
206
  ```

1

ソースコード追加

2017/01/27 02:03

投稿

mogemoge
mogemoge

スコア12

title CHANGED
File without changes
body CHANGED
@@ -29,4 +29,173 @@
29
29
  ###補足情報(言語/FW/ツール等のバージョンなど)
30
30
  ubuntu 15.04 / Rails 5.0.0.1
31
31
 
32
- Railsを始めたばかりなのでどこか勘違いしているのだと思います。よろしくお願いします。
32
+ Railsを始めたばかりなのでどこか勘違いしているのだと思います。よろしくお願いします。
33
+
34
+ ###追記
35
+ 情報を追加します。
36
+
37
+ Gemfile
38
+ ```ここに言語を入力
39
+ source 'https://rubygems.org'
40
+
41
+
42
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
43
+ gem 'rails', '~> 5.0.0'
44
+ # Use sqlite3 as the database for Active Record
45
+ gem 'sqlite3'
46
+ gem 'jquery-rails'
47
+ # Use Puma as the app server
48
+ gem 'puma', '~> 3.0'
49
+ # Use SCSS for stylesheets
50
+ gem 'sass-rails', '~> 5.0'
51
+ # Use Uglifier as compressor for JavaScript assets
52
+ gem 'uglifier', '>= 1.3.0'
53
+ # Use CoffeeScript for .coffee assets and views
54
+ gem 'coffee-rails', '~> 4.2'
55
+ # See https://github.com/rails/execjs#readme for more supported runtimes
56
+ # gem 'therubyracer', platforms: :ruby
57
+
58
+ # Use jquery as the JavaScript library
59
+ gem 'jquery-rails'
60
+ # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
61
+ gem 'turbolinks', '~> 5'
62
+ # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
63
+ gem 'jbuilder', '~> 2.5'
64
+ # Use Redis adapter to run Action Cable in production
65
+ # gem 'redis', '~> 3.0'
66
+ # Use ActiveModel has_secure_password
67
+ gem 'bcrypt', '~> 3.1.7'
68
+
69
+ # Use Capistrano for deployment
70
+ # gem 'capistrano-rails', group: :development
71
+
72
+ group :development, :test do
73
+ # Call 'byebug' anywhere in the code to stop execution and get a debugger console
74
+ gem 'byebug', platform: :mri
75
+ end
76
+
77
+ group :development do
78
+ # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
79
+ gem 'web-console'
80
+ gem 'listen', '~> 3.0.5'
81
+ # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
82
+ gem 'spring'
83
+ gem 'spring-watcher-listen', '~> 2.0.0'
84
+ end
85
+
86
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
87
+ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
88
+ ```
89
+
90
+ questions_controller.rb
91
+ ```Ruby
92
+ class QuestionsController < ApplicationController
93
+
94
+ include AjaxHelper
95
+
96
+ @@answered=false
97
+ @@reload_status='next'
98
+ @@question_set=Question.new
99
+
100
+ def index
101
+ end
102
+
103
+ def show
104
+ @@answered=false
105
+ @@questions=Question.all
106
+ @num_of_questions=@@questions.length
107
+
108
+ @@users=User.where(exist: true)
109
+
110
+ #@question_set||=@@questions.sample
111
+ if @@reload_status=='next'
112
+ margin_max=Float::MAX
113
+ @@questions.each do |q|
114
+ if (current_user.theta-q.b).abs<margin_max
115
+ @margin_max=(current_user.theta-q.b).abs
116
+ @@question_set=q
117
+ end
118
+ end
119
+ @question=@@question_set
120
+ else
121
+ @question=@@questions.sample
122
+ end
123
+
124
+ collects=0
125
+ @@questions.each do |q|
126
+ collects+=eval("q.user#{current_user.number}")
127
+ end
128
+ @accuracy=collects/@@questions.length.to_f
129
+ end
130
+
131
+ def ajax_method
132
+ if params['reload'].present?
133
+ @@reload_status=params['reload']
134
+ end
135
+ respond_to do |format|
136
+ format.js{render ajax_redirect_to "http://localhost:3000/questions/show"}
137
+ end
138
+ end
139
+
140
+ def button
141
+ if params['chosen'].present?&&!@@answered
142
+ if params['chosen']==params['answer']
143
+ @result=1
144
+ else
145
+ @result=0
146
+ end
147
+ @@question_set.update("user#{current_user.number}": @result)
148
+ @@answered=true
149
+ current_user.exist=true
150
+ current_user.save
151
+
152
+ l_theta=Float::MIN
153
+ -3.0.step(3.0,0.1) do |theta_arg|
154
+ tmp_calc=1.0
155
+ @@questions.each do |q|
156
+ 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}"))
157
+ end
158
+ if l_theta<tmp_calc
159
+ current_user.theta=theta_arg
160
+ l_theta=tmp_calc
161
+ end
162
+ end
163
+ current_user.save
164
+ p "updated theta of user#{current_user.number}: "+current_user.theta.to_s
165
+ l_b=Float::MIN
166
+ -3.0.step(3.0,0.1) do |b_arg|
167
+ tmp_calc=1.0
168
+ @@users.each do |u|
169
+ 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}"))
170
+ end
171
+ if l_b<tmp_calc
172
+ @@question_set.b=b_arg
173
+ l_b=tmp_calc
174
+ end
175
+ end
176
+ @@question_set.save
177
+ p "updated b of questions#{@@question_set.qid}: "+@@question_set.b.to_s
178
+
179
+ f=File.open('./db/record.txt', 'w')
180
+ record=""
181
+ @@users.each do |u|
182
+ @@questions.each do |q|
183
+ record+="u_"+u.number.to_s+"_"+q.qid.to_s+"="+eval("q.user#{u.number}").to_s+";"
184
+ end
185
+ end
186
+ f.print encrypt(record)
187
+ f.close
188
+ end
189
+ end
190
+
191
+ def encrypt(word)
192
+ crypt = ActiveSupport::MessageEncryptor.new(SECURE, CIPHER)
193
+ crypt.encrypt_and_sign(word)
194
+ end
195
+
196
+ def decrypt(word)
197
+ crypt = ActiveSupport::MessageEncryptor.new(SECURE, CIPHER)
198
+ crypt.decrypt_and_verify(word)
199
+ end
200
+ end
201
+ ```