0

I have an Issue model and polymorphic attachments association. Pundit is used to handle authorization and strong parameters. When I use simple file input for attachment, like this:

<%= f.simple_fields_for :attachments do |attachments| %>
  <%= attachments.input :file, as: :file %>

everything goes smooth, but when I add multiple for file input, pundit reject this attribute. Here's my permitted attribute method from policy

def permitted_attributes
  [
      :title, :description, :project,
      assigned_users_attributes: [:_destroy, :id, :email],
      attachments_attributes: [:file]
  ]
end

How should I change that to accept multiple file input?

1 Answers1

0

You need to change :file to :file => [] in order to allow multiple values.

def permitted_attributes
  [
    :title, :description, :project,
    assigned_users_attributes: [:_destroy, :id, :email],
    attachments_attributes: [:file => []]
  ]
end
Pavan
  • 33,316
  • 7
  • 50
  • 76