简体   繁体   English

在删除时,我想重定向到Rails的上一页

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

I want to delete the customised item from the list. 我想从列表中删除自定义项目。 I have 5 pages, in each page 6 items each (ie;total 30 items in list(including all pages), so that from 5th page I deleted the 6 items, when I deleted the all 6 items it is saying the your page is empty. Still in other four pagination pages includes the remaining items(26). 我有5页,每页中有6个项目(即列表中总共30个项目(包括所有页面)),因此从第5页起,我删除了6个项目,而当我删除所有6个项目时,则表示您的页面是仍然在其他四个分页中包含其余项目(26)。

Please give me a solution.Any help 请给我一个解决方案。任何帮助

I want to redirect the 4th page, when 5th page items are empty. 当第5页项目为空时,我想重定向第4页。 How can I achieve this? 我该如何实现?

redirect_to :back is not working here redirect_to :back在这里不起作用

my controller page 我的控制器页面

 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 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

Which gem are you using for paginate?. 您使用哪种宝石进行分页? Assuming that you are using "will paginate". 假设您正在使用“将分页”。 You can try this after destroy: 您可以在销毁后尝试以下方法:

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