我已经可以使用下面的代码生成我需要的params数量但是当我提交表单时,返回的数据是索引位置而不是提交的值我似乎无法找到问题它知道输入的是什么我知道错误日志,当我有其他事情搞砸了,但那部分是固定的。
相关前端:
post '/submitpage' do
authentication_required
data = database.execute("select Id,Questions from Questions");
data.each_with_index do |i|
eval(" '#{i[0]}' + '=' + 'params[:q#{i[0]}]' ")
end
name = params[:name]
id = params[:id]
date = params[:date]
time = params[:time]
c1 = params[:comment4]
c2 = params[:comment5]
c3 = params[:"comment6"]
c4 = params[:"comment7"]
c5 = params[:"comment8"]
c6 = params[:"comment9"]
c7 = params[:"comment10"]
c8 = params[:"comment11"]
c9 = params[:"comment12"]
c10 = params[:"comment13"]
database.execute("INSERT INTO Answers (Answer) VALUES ('#{name}'), ('#{id}'),('#{date}'),('#{time}'),('#{1}'),('#{2}'),('#{3}'),('#{4}'), ('#{5}'),('#{6}'),('#{7}'),('#{8}'),('#{9}'), ('#{10}'),('#{11}'),('#{12}'),('#{13}'),('#{14}'),('#{15}'),('#{16}'),('#{17}'),('#{18}'),('#{19}'),('#{20}')");
database.execute("INSERT INTO Comments (Comments) VALUES ('#{c1}'),('{c2}'),('#{c3}'),('#{c4}'),('#{c5}'),('#{c6}'),('#{c7}'),('#{c8}'),('#{c9}'),('#{c10}')");
redirect to('/page1')
end
相关的部分观点:
<div class="row">
<div class="column column-12 scrollingTable ">
<h3>I. Work Evaluation</h3>
<table class="sortable">
<tr>
<th></th>
</tr>
<% data.each.with_index do |data, index| %>
<% if data[0] >= 5 && data[0] <= 19 %>
<tr>
<td><%= data[1] %></td>
<td><select name="q<%= index %>">
<option value=""></option>
<option value="Yes">Yes</option>
<option value="No">No</option>
<option value="na">N/a</option>
</select>
<div class="accordion">Comment</div>
<div class="panel">
<textarea class="comments" name="comment<%= index %>" rows="4" cols="15"> </textarea>
</div>
</td>
</tr>
<% end %>
<% end %>
</table>
<% # some code %>
</div>
</div>