Removing an associated object with a link_to to the update action
- by Numbers
class Question < ActiveRecord::Base
belongs_to :category
end
class Category < ActiveRecord::Base
has_many :questions
accepts_nested_attributes_for :questions, allow_destroy: true
end
CategoriesController:
private
def category_params
params.require(:category).permit(:title, questions_attributes: [:id, :category_id, :title, :_destroy])
end
In the view I have a category displaying all it's posts (CategoriesController#show).
Each post is deletable.
How could I construct a link_to helper that deletes a post by updating the category?