I am using Rails and have a controller for Bills in which there is a destroy method. In the browser, when I use the delete url e.g. localhost/delete/2 (2 in this case is the ID of the relevant bill), the bill never gets deleted. Any ideas on what I could be doing wrong (or if I should additional configs here). The routes is copied below ass well.
bills_controller
def destroy
@bill = Bill.find(params[:id])
@bill.destroy
respond_to do |format|
format.html { redirect_to posts_url, notice: 'Bill was successfully destroyed.' }
format.json { head :no_content }
end
end
Routes:
Rails.application.routes.draw do
resources :posts
get 'posts/index'
end
Should I be adding a specific route for the delete action in the routes.rb file? I have the following on my HTML page:
<td><a data-confirm="Are you sure?" rel="nofollow" data-method="delete" href="/bills/1">Destroy</a></td>
Aucun commentaire:
Enregistrer un commentaire