我是rails和jQuery的初学者。 我在一个页面中有两个单独的表单,我想以ajax方式(使用jQuery)单独提交它们。 这是我得到了多远。 任何人都可以添加或修复此代码以使其工作。 我正在使用Rails 3.1和jQuery 1.6。 先感谢您。
的application.js
$(".savebutton").click(function() {
$('form').submit(function() {
$(this).serialize();
});
});
第一种形式:
Basic details
"45",:class=>"round",:id=>"school" %>
"savebutton"} %>
第二种形式:
Your current classes
class:"45",:class=>"round" %>
"savebutton"} %>
SchoolController
class SchoolController < ApplicationController
respond_to :json
def create
@school = current_user.posts.build(params[:school].merge(:user => current_user))
if @school.save
respond_with @school
else
respond_with @school.errors, :status => :unprocessable_entity
end
end
end
CourseController与SchoolController的形状相同