Removing an associated object with a link_to to the update action

Posted by Numbers on Stack Overflow See other posts from Stack Overflow or by Numbers
Published on 2014-06-02T21:18:13Z Indexed on 2014/06/02 21:25 UTC
Read the original article Hit count: 109

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-4