2016-05-06 5 views
2

ich diese Parameter in meinem Rails-Controller bekommen:Warum bekomme ich "Unerreichter Parameter: Format"?

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"}} 

Doch bekomme ich diese Meldung: Unpermitted parameter: format

Auch wenn ich verwende:

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]) 
+1

Können Sie Ihre Modellzuordnungen für verschachtelte Attribute (poll_pages) anzeigen? –

+0

Sie enthält wahrscheinlich das angeforderte Antwortformat wie 'json'. Sie können den Inhalt von Parametern in Ihrem Controller überprüfen. – mlt

Antwort

0

Sie müssen permitte in stark Params das "Format", es ist in Form, aber kann keinen Wert speichern, bis dies erlaubt.

1

müssen Sie wie richtiges Format senden:

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]) 

Und auch _attributes für die verschachtelten Attribute in Ihrer Erlaubnis params:

poll_attributes: [:id, :user_id, :title, :description, :state_id, :group_id, :allow_anonymous_answer, :initial_message, :final_message] 
-1

Ich weiß, diese Frage ist alt, aber ich hatte ein ähnliches Problem und fand eine Lösung. Zusätzlich zu dem, was Sunny erwähnte, musste ich die Hilfsmethode "inverse_of" in meinen beiden Modellen verwenden.