Nested simple_form with polymorphic association. Unpermited parameter

自作多情 提交于 2019-12-12 06:01:57

问题


It's a lot of question about it all around, but I can't find the answer. I've:

group.rb

class Group < ActiveRecord::Base
  has_many :descriptions, :as => :describable
  accepts_nested_attributes_for :descriptions
end

description.rb

class Description < ActiveRecord::Base
  belongs_to :describable, :polymorphic => true
end

groups_controller.rb

   def update
        @group = Group.find(params[:id])
        if @group.update_attributes(group_params)
          flash[:success] = "yes"
          redirect_to groups_path
        else
          render 'edit'
        end
   end


   private

      def group_params
        params.require(:group).permit(:owner_id, :domain, descriptions_attributes: [:id, :content])
 end

edit.html.erb

<%= simple_form_for @group do |f| %>
    <% if @group[:domain].blank? %>
        <%= f.input :domain %>
    <% else %>
        <%= f.input :domain, readonly: true %>
    <% end %>
    <%= f.input :owner_id, readonly: true %>
    <%= f.simple_fields_for :descriptions do |description| %>
        <%= description.input :content %>
    <% end %>
    <%= f.button :submit %>
<% end %>

In console I've Unpermitted parameter: description and nested attribute does not created. What should I do to save it at last?


回答1:


I suppose Rails does not convert form name to names_attributes when generating form for nested polymorphic connection, this:

... description: [:content, :other_param, ...]

Works fine for me for polymorphic child.



来源:https://stackoverflow.com/questions/34231414/nested-simple-form-with-polymorphic-association-unpermited-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!