I've got a link_to meant to destroy a record:
<%= link_to 'Delete from DB', {:controller => 'foos', :action => 'destroy', :id => foo.id}, :class => "btn btn-primary btn-mini" %>
The destroy method in the controller:
def destroy
@foo = Foo.find(params[:id])
@foo.destroy
respond_to do |format|
format.html { redirect_to :back }
format.json { head :no_content }
end
end
Pressing the button doesn't delete the record, but if I open up rails console and call .destroy
on an existing foo, it is removed from the DB.
Let me know if you see a mistake here. Thanks.
It's probably because you send
GET
request while you need to sentDELETE
request in order to calldestroy
action. So, your link should look: