0
使用Rails 4.2.3。通常,在一個動作中,我希望執行Ajax調用,並用JS進行響應(使用JS來更新某個字段),並且不希望它響應HTML。例如:必須僅在以下情況下指定respond_to:html:預計使用js
def create
@post = Post.new(params[:post])
if @post.save
respond_to do |format|
format.html
format.js
end
end
end
是format.html
仍然有必要嗎?我通常只使用下面的代碼來代替:
def create
@post = Post.new(params[:post])
@post.save
end
,並創建一個create.js
鑑於上呈現。到目前爲止沒有問題,但這是一個好習慣嗎?