Ruby on rails 验证jQuery,远程在Rails 3中重定向错误
在application.js中Ruby on rails 验证jQuery,远程在Rails 3中重定向错误,ruby-on-rails,jquery-validate,Ruby On Rails,Jquery Validate,在application.js中 $(document).ready(function () { $("#new_academic_formation").validate({ debug: true, rules: { "academic_formation[id]": { required: true, minlength: 3, remote: "/academic_formations/check_id" } }
$(document).ready(function () {
$("#new_academic_formation").validate({
debug: true,
rules: {
"academic_formation[id]": {
required: true,
minlength: 3,
remote: "/academic_formations/check_id"
}
}
});
});
在我的学术报告中_formations _controller.rb
def check_id
@academic_formation = AcademicFormation.find(params[:id])
respond_to do |format|
format.json { render :json => !@academic_formation }
end
end
最后是文件routes.rb
resources :academic_formations
match "/academic_formations/check_id" => 'academic_formations#check_id'
问题是rails没有调用action check\u id,而是调用action show 您需要在
资源:学术团队
之前移动匹配//学术团队/检查团队id”=>“学术团队#检查团队id”
这是直接从报纸上发来的
Rails路由是按指定的顺序匹配的,因此,如果在get'photos/poll'
上有一个resources:photos
,则显示操作的资源行路由将在get行之前匹配。若要解决此问题,请将get行移到resources行上方,以便首先匹配它
或
由于您的路由资源丰富,如果它适用于某个集合(您可以在上面链接的文档中阅读更多关于该集合的信息),如果它是get
方法,您可以添加一个路由,如下所示:
resources :academic_formations do
collection do
get 'check_id'
end
end