簡體   English   中英

在刪除時,我想重定向到Rails的上一頁

[英]On delete I want to redirect to the previous page in rails

我想從列表中刪除自定義項目。 我有5頁,每頁中有6個項目(即列表中總共30個項目(包括所有頁面)),因此從第5頁起,我刪除了6個項目,而當我刪除所有6個項目時,則表示您的頁面是仍然在其他四個分頁中包含其余項目(26)。

請給我一個解決方案。任何幫助

當第5頁項目為空時,我想重定向第4頁。 我該如何實現?

redirect_to :back在這里不起作用

我的控制器頁面

 def destroy
    @customised_dresses = CustomisedDress.where(user_id: current_user.id, id: params[:id]).first
    respond_to do |format|
      if @customised_dresses.present?
        @customised_dresses.destroy
        format.html { redirect_to :back, notice: "Customised dress has been successfully destroyed" }
      else
        format.html { redirect_to :back, notice: 'You have no customised item.' }
      end
    end
 end

mycustomisations.html.slim- - if @customises - if @customises.empty? You have no items in your list = link_to 'Customise Dress', :customise_index, class: 'btn btn-primary' - else = paginate @customises - if @customises - if @customises.empty? You have no items in your list = link_to 'Customise Dress', :customise_index, class: 'btn btn-primary' - else = paginate @customises

您使用哪種寶石進行分頁? 假設您正在使用“將分頁”。 您可以在銷毀后嘗試以下方法:

last_page = @customises.total_pages
redirect_to: your_path(page: last_page)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM