简体   繁体   中英

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

Please give me a solution.Any help

I want to redirect the 4th page, when 5th page items are empty. How can I achieve this?

redirect_to :back is not working here

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM