未允许的参数:_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
我正在删除表单上的字段点击罚款,但记录尚未删除.
谢谢
编辑:Js设置隐藏变量
jquery -> $(document).on 'click',".remove_fIElds",(event) -> $(this).prev('input[type=hIDden]').val('1') $(this).closest('fIEldset').hIDe() event.preventDefault()解决方法 @Hitham S. AlQadheeb可能是对的 – 检查你的模型是否正确……
survey.rb
class Survey < ActiveRecord::Base has_many :questions,:dependent => :destroy accepts_nested_attributes_for :questionsend
和问题.rb
class Question < ActiveRecord::Base belongs_to :survey has_many :answers,:dependent => :destroy accepts_nested_attributes_for :answers,:reject_if => lambda { |a| a[:content].blank? },:allow_destroy => trueend
不允许的参数:_destroy错误实际上应该指的是你的控制器的强参数的实现:survey_params.你需要告诉rails你的表单将传递:_destroy字段.试试这个:
def survey_params params.require(:survey).permit(:name,:_destroy,:response,:_destroy]]) end---------------------------------------------------------------------------------^-------------------------------------------------------------------------------------------------------------------------------------^总结
以上是内存溢出为你收集整理的ruby-on-rails – 删除嵌套属性时未允许的属性_destroy全部内容,希望文章能够帮你解决ruby-on-rails – 删除嵌套属性时未允许的属性_destroy所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)