【问题标题】:Nested simple_form with polymorphic association. Unpermited parameter具有多态关联的嵌套 simple_form。不允许的参数
【发布时间】:2015-12-11 19:48:47
【问题描述】:

关于它的问题很多,但我找不到答案。 我已经:

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 并且没有创建嵌套属性。最后我该怎么做才能保存它?

【问题讨论】:

    标签: ruby-on-rails simple-form nested-attributes polymorphic-associations


    【解决方案1】:

    我想 Rails 在为嵌套多态连接生成表单时不会将表单 name 转换为 names_attributes,这是:

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

    对于多态孩子来说对我来说很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-01
      相关资源
      最近更新 更多