Rails。销毁项目后 SmartListing gem 不刷新 table

Rails. SmartListing gem doesn't refresh table after destroying item

我的页面有 table 个类别。我正在使用 SmartListing GEM 对数据进行排序,我还为 table 中的每个项目添加了一些按钮,包括 "delete" 按钮。

问题: 删除table中的元素后,table闪烁但不刷新数据,所以我需要重新加载漏洞页面以获取更新 table。 (顺便说一句,从数据库中删除元素没有问题)

我的文件看起来像 developer example 中的文件。


我的文件:

索引和销毁 CategoriesController

中的操作
def index
  @categories = Category.all
  smart_listing_create :categories, @categories,
                       sort_attributes: [
                         [:created_at, 'categories.created_at'],
                         [:updated_at, 'categories.updated_at'],
                         [:name, 'categories.name'],
                         [:calculate, 'categories.issues_count']
                       ],
                       default_sort: { name: 'asc' }, partial: 'category'
end

def destroy
  @category = Category.find(params[:id])
  if @category.issues.empty?
    @category.destroy
    flash[:success] = 'Deleted'
  else
    flash[:alert] = 'Category isn\'t empty!'
  end
end

index.html.slim

#heading-breadcrumbs
  .container
    .row
      .col-md-7
        h1=title 'Categories'
      .col-md-5
        ul.breadcrumb
          li= link_to 'Main', root_path
          li Categories
#content
  .container
    .row
      #categories-moderation.col-md-12.col-sm-12.col-xs-12
        = link_to 'Create new', new_account_admin_category_path, class: "newcategory btn btn-lg btn-info"
        = smart_listing_render(:categories)

_category.html.slim

- unless smart_listing.empty?
  .table-responsive
    table.table.table-hover.flex-table
      thead
        tr.centered
          th.col-md-2.col-sm-3
            = smart_listing.sortable 'Created', :created_at
          th.col-md-2.col-sm-3
            = smart_listing.sortable 'Updated', :updated_at
          th.col-md-4.col-sm-3
            = smart_listing.sortable 'Title', :name
          th.col-md-2.col-sm-2.hidden-title
            = smart_listing.sortable 'Issues', :calculate
          th.col-md-2.col-sm-2.hidden-title
            | Actions
      tbody
        - smart_listing.collection.each do |category|
          tr.editable[data-id=category.id]
            = smart_listing.render object: category, partial: 'category_item', locals: {object: category}
  = smart_listing.paginate
- else
  p Empty

_category_item.html.slim

tr.centered
  td.col-md-2.col-sm-3.col-xs-12.flex-order-0
    span.user-label Created:
    = object.created_at.strftime("%m.%d.%Y, %T")
  td.td.col-md-2.col-sm-3.col-xs-12.flex-order-1
    span.user-label Updated:
    = object.updated_at.strftime("%m.%d.%Y, %T")
  td.lefted.col-md-4.col-sm-2.col-xs-12.flex-order-2
    = link_to object.name, object
  td.issues_count.col-md-2.col-sm-5.col-xs-12.flex-order-3
    span.user-label Issues:
    = render partial: 'shared/number_of_issues', locals: { id: object.id }
  td.actions.col-md-4.col-sm-5.col-xs-12.flex-order-4
    = smart_listing_item_actions [{name: :edit,
                                   url: edit_account_admin_category_path(object),
                                   icon: 'glyphicon glyphicon-pencil',
                                   title: 'Edit'},
                                  {name: :destroy,
                                   url: account_admin_category_path(object),
                                   confirmation: 'Sure?',
                                   icon: 'glyphicon glyphicon-trash',
                                   remote: true, if: object.issue_ids.empty?,
                                   title: 'Delete'}]

index.js.erb

<%= smart_listing_update(:categories) %>

update.js.erb

<%= smart_listing_item :categories, :update, @category, 'category_item' %>

destroy.js.erb

<%= smart_listing_item :categories, :destroy, @category %>

问题: 删除table中的元素后,table闪烁但不刷新数据,所以我需要重新加载漏洞页面以获取更新 table。 (顺便说一句,从数据库中删除元素没有问题)

我找到了解决问题的方法。它被简单地解决了 - 只需添加到 destroy 操作行 redirect_to action: 'index', status: 303,所以这个操作应该如下所示:

def destroy
  @category = Category.find(params[:id])
  if @category.issues.empty?
    @category.destroy
    flash[:success] = 'Deleted'
    redirect_to action: 'index', status: 303
  else
    flash[:alert] = 'Category isn\'t empty!'
  end
end