0
我正在創建一個ajax表單,它將在我的rails應用程序中成功完成'create'方法後執行幾個函數。它圍繞查找單詞的定義,顯示它們,然後在用戶保存其所需定義後將其從屏幕上移除。我遇到的問題是從success.js.erb訪問函數rollUp和revertButtons(存儲在words.js中)。我甚至試着把這些函數放在application.js中,但它仍然不起作用。現在,當這些函數包含在文件中時,success.js.erb甚至不會執行......任何想法?'create'方法完成後呈現javascript
創建行動:
if @word.save!
params['word_definition'].each do |definition|
if @word.definitions.create(text: definition)
numDefs += 1
end
end
respond_to do |format|
if numDefs > 0
format.js { render action: "success" }
end
end
else
format.js { render action: "failure" }
end
words.js:
function submitForm(){
if(isSubmittable()){
$('#findWord form').serialize();
$('#findWord form').submit();
}
}
// other functions, like revertButtons() and rollUp() are stored here too
success.js.erb:
revertButtons();
rollUp();
$('<div />', { class: "alert alert-success",
text: "The word has been saved",
}).wrap('<div class="single_error" />').parent().appendTo("#fieldAndErrorsContainer");