【发布时间】:2018-05-30 18:25:06
【问题描述】:
以下代码抛出此错误:
不允许的参数::conversation
在post_params 中有conversation_attributes 是否不允许conversations?我做错了什么?
posts_controller.rb
@post = @character.posts.create(post_params)
...
def post_params
params.require(:post).permit( conversation_attributes: [ missives_attributes: [ :content ] ] )
end
post.rb
has_one :conversation, class_name: 'Postconversation', dependent: :destroy
accepts_nested_attributes_for :conversation
postconversation.rb
has_many :missives, class_name: 'Postmissive', dependent: :destroy
accepts_nested_attributes_for :missives
_post_form.html.erb
<%= f.fields_for :conversation do |ff| %>
<%= ff.fields_for :missives do |fff| %>
<%= hidden_field_tag :callsign, character.callsign %>
<%= fff.text_area :content %>
...
<% end %>
<% end %>
日志
Parameters: {"utf8"=>"✓", "authenticity_token"=>"mxHD...VoA==", "callsign"=>"baz", "post"=>{"conversation_attributes"=>{"missives_attributes"=>{"content"=>"Hello"}}}}
【问题讨论】:
标签: ruby-on-rails