我想從列表中刪除自定義項目。我有5頁,每頁每個項目(即;總共30個項目在列表中(包括所有頁面),這樣從第5頁我刪除了6個項目,當我刪除所有6個項目時,它說你的頁面是空的。還有在其他四個分頁頁面包括剩餘的項目(26)。關於刪除我想重定向到rails中的上一頁
請給我一個solution.Any幫助
我想重定向第4頁,當第5頁的項目是空的。怎麼能我做到這一點?
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
5頁x每頁6項 - 這是30項,而不是20.你的號碼中的東西是錯誤的。 –
謝謝@Sergio Tulentsev – SreRoR
我認爲這應該在你的'index'操作中處理。如果您請求的頁面不存在,請改爲顯示上一個現有頁面。 –