Ruby on rails 4 强参数和回形针多上传问题

Ruby on rails 4 强参数和回形针多上传问题,ruby-on-rails-4,paperclip,strong-parameters,multi-upload,Ruby On Rails 4,Paperclip,Strong Parameters,Multi Upload,我曾尝试在模型演示文稿中添加多个图像和视频,但当我提交表单时,控制台会显示: Unpermitted parameters: video Unpermitted parameters: image 演示文稿.rb class Presentation < ActiveRecord::Base belongs_to :formation has_many :videos, :dependent => :destroy has_many :slides, :depend

我曾尝试在模型演示文稿中添加多个图像和视频,但当我提交表单时,控制台会显示:

Unpermitted parameters: video 

Unpermitted parameters: image
演示文稿.rb

class Presentation < ActiveRecord::Base
  belongs_to :formation
  has_many :videos, :dependent => :destroy
  has_many :slides, :dependent => :destroy

  accepts_nested_attributes_for :videos
  accepts_nested_attributes_for :slides
end
class Slide < ActiveRecord::Base
  belongs_to :presentation

  has_attached_file :image
  do_not_validate_attachment_file_type :image
end
它是有效的:)


Skorn.

尝试将
:视频,:图像添加到
演示参数中
方法我已经尝试过了。它不起作用:(尝试将:id添加到演示参数上的嵌套属性中。例如:videos\u attributes:[:id,:video,:\u destroy](与video相同)您尝试了最后一个吗?
class Video < ActiveRecord::Base
  belongs_to :presentation
  has_attached_file :video
  do_not_validate_attachment_file_type :video
end
class PresentationController < ApplicationController
  def new


   @formation = Formation.find(params[:id])
    @presentation = Presentation.new
    @presentation.videos.build
    @presentation.slides.build
  end

  def create
    @formation = Formation.find(params[:id])
    @presentation = @formation.presentations.new(presentation_params)
    if @presentation.save
      redirect_to formations_show_path(@formation)
    else
      render action: 'new'
    end
  end

  def destroy
    @formation = Formation.find(params[:id])
    Presentation.find(params[:pres]).destroy
    redirect_to formations_show_path(@formation)
  end

  private

  def presentation_params
    params.require(:presentation).permit(:name, :description,videos_attributes: [:video], slides_attributes: [:image])
  end
end
<div class="container contenu">
   <div class="row">
      <h1>Création d'une présentation</h1>
        <%= form_for(@presentation, :url => presentations_create_path, html: { multipart: true }, :class=>"form-horizontal") do |f| %>
          <% if @presentation.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@presentation.errors.count, "error") %> prohibited this survey from being saved:</h2>
<ul>
<% @presentation.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>



<div class="form-group">
 <%= f.label :name, :class => "col-sm-2 control-label" %>
 <div class="col-sm-10">
   <%= f.text_field :name, :class =>"form-control" %>
 </div>
</div>
<div class="form-group">
  <%= f.label :description, :class => "col-sm-2 control-label" %>
  <div class="col-sm-10">
     <%= f.text_area :description, :row => "3",:class =>"form-control" %>
  </div>
</div>
<div class="form-group">
   <%= f.fields_for :videos do |v| %>
    <%= v.label :video, :class => "col-sm-2 control-label" %>
    <div class="col-sm-10">
      <%= v.file_field :video, multiple: true,  :class =>"form-control"%>
    </div>
    <% end %>
</div>
<div class="form-group">
   <%= f.fields_for :slides do |s| %>
    <%= s.label :image, :class => "col-sm-2 control-label" %>
    <div class="col-sm-10">
      <%= s.file_field :image, multiple: true, :class =>"form-control"%>
    </div>
    <% end %>
</div>
<div class="form-group">
 <div class="col-sm-offset-2 col-sm-10">
    <%= f.submit :class => "btn btn-default"%>
 </div>
</div>
        <% end %>
        <%= link_to 'retour', formations_show_path(@formation) %>
   </div>
</div>
  <%= v.file_field :video, multiple: true,:name =>"presentation[videos_attributes][][video]",  :class =>"form-control"%>