Routing Errors on attempts to delete all records in a table using Rails 4 through a link_to -
i using rails 4, , trying delete assessments using link_to helper. pertinent code below:
routes.rb
resources :assessments collection delete :remove_all end end
assessment index.html.erb
<p>to delete assessments in 1 swoop, click <%= link_to 'remove assessments', remove_all_assessments_path, method: :destroy, data: { confirm: 'are sure?' } %>
assessments_controller.rb
def remove_all @assessments = assessment.all @assessments.each |assessment| assessment.destroy(assessment.id) end flash[:notice] = "all assessments have been deleted." redirect_to assessments_url end
i run rake routes
,
prefix verb uri pattern controller#action remove_all_assessments delete /assessments/remove_all(.:format) assessments#remove_all
the html source generated link:
<p>to delete assessments in 1 swoop, click <a data-confirm="are sure?" data-method="destroy" href="/assessments/remove_all" rel="nofollow">remove assessments</a>
when click on 'remove assessments' link, expect have remove_all action run in assessmentscontroller, , delete assessments in @assessments, redirect me assessments_url. however, when click on 'remove assessments', link, brought url: http://localhost:3000/assessments/remove_all
error no route matches [post] "/assessments/remove_all"
what gives?
it should <p>to delete assessments in 1 swoop, click <%= link_to 'remove assessments', remove_all_assessments_path, method: :delete, data: { confirm: 'are sure?' } %>
Comments
Post a Comment