我对jQuery / Ajax没什么了解。有人可以帮我动态提交表格
这是要求: - 我有一套测试 - 每个测试都有结果 - 每个测试结果存储为单独的记录
我正在考虑以下方法: - 将每个测试结果显示为单独的表单,并使用AJAX提交每个测试结果
我希望有更好的方法,请帮助我
这是我的代码:
//results controller
class ResultsController < ApplicationController
def index
@results = Result.all
@tests = Tests.all
end
def new
@result = Result.new
end
//view
@tests.each do |test|
= form_for(@result) do |r|
= r.label :test_id, test.name
= r.hidden_field :test_id, :value => test_id
= r.select :status, options_for_select(%w[UNTESTED PASS FAIL PENDING BLOCKED INVALID])
= r.submit "Submit"
答案 0 :(得分:0)
来自控制器的索引操作将调用索引页面 在索引页面
= @tests.each do |test|
#test.#{test.id}= render partial: "test", :locals => {test: test}
创建一个_test.html页面在_test页面中执行所有这些操作,
= form_for(test) do |test|
= r.label :test_id, test.name
= r.hidden_field :test_id, :value => test_id
= r.select :status, options_for_select(%w[UNTESTED PASS FAIL PENDING BLOCKED INVALID])
= r.submit "Submit"
创建一个index.js.html文件
:plain
$("#test_#{@test.id}").html("#{escape_javascript(render(:partial => "test", :locals => { :test => @test}))}");