我在Rails控制器中获取这些参数:
Parameters: {"id"=>"238", "user_id"=>1, "group_id"=>43, "title"=>"asdasdasd 1111 ultadas ult asdas", "description"=>"asdssss", "state_id"=>nil, "allow_anonymous_answer"=>false, "initial_message"=>"asdasdsadas", "final_message"=>"dasdasdsad", "poll_pages"=>[{"id"=>382, "poll_id"=>238, "title"=>"Pagina 1", "description"=>"Pagina 1", "position"=>1, "created_at"=>"2016-05-06T14:25:56.795Z", "updated_at"=>"2016-05-06T14:25:56.795Z"}], "poll"=>{"id"=>"238", "user_id"=>1, "group_id"=>43, "title"=>"asdasdasd 1111 ultadas ult asdas", "description"=>"asdssss", "state_id"=>nil, "allow_anonymous_answer"=>false, "initial_message"=>"asdasdsadas", "final_message"=>"dasdasdsad"}}
然而我收到了这条消息:Unpermitted parameter: format
即使我正在使用:
params.permit(:id, :user_id, :title, :description, :state_id, :group_id, :allow_anonymous_answer, :initial_message, :final_message, poll: [:id, :user_id, :title, :description, :state_id, :group_id, :allow_anonymous_answer, :initial_message, :final_message], poll_pages: [:id, :poll_id, :title, :description, :position, :created_at, :updated_at])
答案 0 :(得分:1)
您需要发送正确的格式,如:
params.require(:MODEL).permit(:id, :user_id, :title, :description, :state_id, :group_id, :allow_anonymous_answer, :initial_message, :final_message, poll_attributes: [:id, :user_id, :title, :description, :state_id, :group_id, :allow_anonymous_answer, :initial_message, :final_message], poll_pages_attributes: [:id, :poll_id, :title, :description, :position, :created_at, :updated_at])
还有 _attributes ,用于许可证参数中的嵌套属性 :
poll_attributes: [:id, :user_id, :title, :description, :state_id, :group_id, :allow_anonymous_answer, :initial_message, :final_message]
答案 1 :(得分:0)
你需要在强制参数中使用“格式”,这是形式,但是在允许这样做之前不能保存任何值。
答案 2 :(得分:-1)
我知道这个问题很老,但我遇到了类似的问题,并找到了解决方案。除了Sunny提到的,我不得不使用" inverse_of"我的两个模型中的辅助方法。