0

Это очень много об этом, но я не могу найти ответ. Я:Вложенная simple_form с полиморфной ассоциацией. Непереведенный параметр

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 %> 

В консоли Я Unpermitted parameter: description и вложенный атрибут не создается. Что мне делать, чтобы сохранить его наконец?

ответ

0

Я полагаю, Rails не преобразует форму name в names_attributes при создании формы для вложенной полиморфной связи, это:

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

отлично работает для меня для полиморфного ребенка.

Смежные вопросы