Following railscasts # 196, but using Rails 4 - I have a problem trying to remove the answer from the parent model of the question.
Parameters not listed: _destroy
_answer_fields.html.erb
<fieldset>
<%= f.text_field :response %>
<%= f.hidden_field :_destroy %>
<%= link_to "remove" , "#", class: "remove_fields" %>
</fieldset>
question.rb
accepts_nested_attributes_for :questions, :allow_destroy => true
surveys_controller.rb
def survey_params
params.require(:survey).permit(:name, :questions_attributes => [:id, :content, :answers_attributes => [:id, :response]])
end
I remove the fields from the form on click, but the record is not deleted.
thanks
Edit: JS to set a hidden variable
jQuery ->
$(document).on 'click' , ".remove_fields" , (event) ->
$(this).prev('input[type=hidden]').val('1')
$(this).closest('fieldset').hide()
event.preventDefault()
Mikew source
share