0
我有一個銷燬方法的問題。我的想法是重新渲染部分,但部分應該做檢查if @driving_informations.present?
。所以當我點擊鏈接「刪除」頁面什麼也不做,數據停留在頁面上,當我按F5和頁面重新載入一切正常 - 數據不存在!渲染一些局部摧毀後的方法。 Rails,haml
這是我的控制器方法
def destroy
@driving_information.destroy
@user = @driving_information.user
@driving_informations = @user.driving_informations
render '_list.html.haml', layout: false
end
,並查看
%h4= t("driving_information.driving_info")
-if @driving_informations.present?
=render ("list")
-if @user == current_user
- @driving_informations.each do |driving_information|
= link_to t('common.edit'), edit_driving_information_path(driving_information), remote: true, data: { toggle: "modal", target: "#ajax-modal" }
= link_to t('common.delete'), driving_information_path(driving_information), method: :delete, remote: true, data: { confirm: t('common.confirm') }
-else
= link_to t('common.add'), new_driving_information_path, remote: true, data: { toggle: "modal", target: "#ajax-modal" } if @user == current_user
%p= t('driving_information.not_exists') if @user != current_user
:javascript
$(function(){
$("table.driving-information .destroy-btn").on("ajax:success", function(event, data, status, xhr){
$('#driving-information-block').html(data);
任何想法?
您在HAML表有'driving_information'(帶下劃線)(如果我正確地讀它,我不知道HAML),但'駕駛信息'(帶破折號)在JavaScript中,也許這就是爲什麼js不被稱爲? – zrl3dx
不,js只用於flash消息 –