我有Competency和CompetencyType模型。在新Competency的表单中,我想添加一个单独的字段Add new competency type,它将创建新的CompetencyType。
= label_tag :title, t('competency.add_type'), class: 'control-label'
= text_field :title, nil, class: 'span12'
= submit_tag "Add", id: 'competency_type'
如何创建新的CompetencyType的Ajax请求?
答案 0 :(得分:1)
1解决方案 添加到表格remote:true
2)
$(window).ready(function(){
$("form").submit(function(e){
$.ajax({
type: "POST",
url: path,
data: { 'title': $('title') }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
});
});