Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Refresh page after deleting

I have this:

<%= link_to 'Delete', post , method: :delete, data: { confirm: 'Are you sure?' } %>

After clicking, Rails deletes the current record post.

I want refresh current page after deleting.

like image 980
tencet Avatar asked Mar 12 '15 12:03

tencet


2 Answers

At your controller destroy method use the current page's url for redirect.

def destroy
    @object.destroy
    respond_to do |format|
      format.html { redirect_to current_page_url, notice: 'page was successfully destroyed.' }
      format.json { head :no_content }
    end
  end
like image 158
Emu Avatar answered Nov 02 '22 03:11

Emu


in Rails 5 you can do:

redirect_back(fallback_location: root_path) 
like image 33
sloneorzeszki Avatar answered Nov 02 '22 04:11

sloneorzeszki