我对销毁方法有疑问。我的想法是重新渲染部分,但部分应该做检查if @driving_informations.present?
。因此,当我单击链接“删除”页面时什么都不做,并且数据留在页面中,当我按 F5 并重新加载页面时,一切正常 - 数据不存在!
这是我的控制器方法
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);
有任何想法吗?