在我的Rails應用程序,我想阻止用戶刪除一個帖子給出一些條件。發生這種情況時,我只想告訴他們該帖子無法刪除。代碼如下所示:Rails,js響應,只有一個通知
def destroy
respond_to do |format|
if some_conditions
flash[:notice] = "Could not be deleted"
...
format.js {What to put here}
else
...
end
end
end
我應該把在js響應括號什麼讓頁面不重新加載,但顯示的通知?謝謝!
我得到一個錯誤信息 「缺少模板帖/銷燬」。哦,我忘了destroy.js.erb ... –
你有沒有添加js.erb – Sravan