Reputation: 105
I have this entry that I am trying to delete from the index page where all the entries are listed in rails 4.
controller code:
def destroy
@entry.destroy
respond_to do |format|
format.html{ redirect_to :action => :index}
end
end
View code:
<%entry ||= Entry.new(:date => Time.new)
id = dom_id entry%>
-SOME-CODE-IN-HERE
<%= link_to image_tag("delete.png"), {:action => :destroy, :id => entry},
data:{:confirm => "Are you sure to delete this entry?"}, method:
:delete, remote: true %>
When I click on the delete image the entry is getting deleted from the database but the page does not refresh.It still shows the old deleted entry till the page is refreshed manually. Could some on please help me to automatically redirect the page to index after the entry is deleted. Any help would be appreciated.
Upvotes: 0
Views: 45
Reputation: 10111
the problem that you are having is you are making a remote call to the server with remote: true
this makes a ajax call and does not bind it back to the browser.
<%= link_to image_tag("delete.png"), {:action => :destroy, :id => entry}, data:{:confirm => "Are you sure to delete this entry?"}, method: :delete %>
You can read more about remote-elements
Upvotes: 1