SkRoR
SkRoR

Reputation: 1199

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

Upvotes: 0

Views: 473

Answers (1)

Prakash Laxkar
Prakash Laxkar

Reputation: 854

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)

Upvotes: 1

Related Questions