Reputation: 1855
Fairly new to rails and can't seem to get this simple destroy action working. All it does is redirect to the mod panel index page and doesn't destroy the record. Do I need to call .destroy
in the destroy method? or is there something I'm missing?
mod_approval controller
def index
@guide = Guide.friendly.find(params[:guide_id])
@check_category = CheckCategory.where(guide_id: @guide.id).all
@category = Guide.friendly.find(@guide.id).categories.new
end
def destroy
redirect_to guide_mod_panel_mod_approval_index_path(@guide)
end
config/routes.rb
match '/guides/:guide_id/mod-panel/approve/reject' => 'mod_approval#destroy', :via => :delete, as: :guide_mod_panel_approve_destroy
index.html.erb
<% @check_category.each do |category| %>
<%= link_to "Reject", guide_mod_panel_approve_destroy_path(@guide, category), method: :delete, data: {confirm: "You sure?"} %><br>
<% end %>
Upvotes: 0
Views: 145
Reputation: 17834
You need to fetch the record from the database, then you can call destroy on the object, you can do this
def destroy
guide = Guide.find(params[:guide_id])
category = guide.categories.find(params[:id])
category.destroy
redirect_to guide_mod_panel_mod_approval_index_path(guide)
end
Hope that helps!
Upvotes: 1
Reputation: 3722
You should have to destroy object before:
def destroy
@destroyed_object.destroy # or Model.destroy(params[:id])
redirect_to guide_mod_panel_mod_approval_index_path(@guide)
end
Upvotes: 0