Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails RubyonRails—向嵌套表单添加附件。未提交/保存_Ruby On Rails_Paperclip_Simple Form - Fatal编程技术网

Ruby on rails RubyonRails—向嵌套表单添加附件。未提交/保存

Ruby on rails RubyonRails—向嵌套表单添加附件。未提交/保存,ruby-on-rails,paperclip,simple-form,Ruby On Rails,Paperclip,Simple Form,我有一个应用程序,其中有一个“Gig”模型,它由许多“歌曲”组成。 我希望每首歌曲都有一个用户必须上传的歌曲文件 我刚刚安装了回形针gem(打算很快添加AWS),但是一旦我添加了,Gig表单上的“提交”按钮就不再工作了 如果我没有附加文件,“提交”工作正常,“歌曲”更新。但是,只要我选择了一个要上传的文件,单击按钮什么也不做 我不知道我对博克做了什么。。。任何帮助都将不胜感激 在C9.io上工作 宝石 source 'https://rubygems.org' gem "paperclip",

我有一个应用程序,其中有一个“Gig”模型,它由许多“歌曲”组成。 我希望每首歌曲都有一个用户必须上传的歌曲文件

我刚刚安装了回形针gem(打算很快添加AWS),但是一旦我添加了
,Gig表单上的“提交”按钮就不再工作了

如果我没有附加文件,“提交”工作正常,“歌曲”更新。但是,只要我选择了一个要上传的文件,单击按钮什么也不做

我不知道我对博克做了什么。。。任何帮助都将不胜感激

在C9.io上工作

宝石

source 'https://rubygems.org'

gem "paperclip", "~> 4.2"
gem 'cocoon'
gem 'simple_form'
gem 'twitter-bootstrap-rails'
gem 'devise'
etc...
def gig_params
      params.require(:gig).permit(:gig_name, :gig_date, songs_attributes: [:id, :name, :singfile, :song_file ])
    end
Gig/_form.html.erb

<div class="col-md-6">
  <h2>Define the gig</h2>

<%= simple_form_for(@gig) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :gig_name %>
    <%= f.input :gig_date, class: "input-append date form_datetime" %>
  </div>
</div>
<div class="col-md-6">
  <h2>Add the songs</h2>

    <%= f.simple_fields_for(:songs) do |song| %>
      <%= render 'song_fields', :f => song %>
    <% end %>
    <div class="links">
      <%= link_to_add_association 'Add Another Song', f, :songs, class: "btn btn-primary col-md-8 col-md-offset-4" %>
    </div>
    <br>
    </div>
  <div class="form-actions">
    <%= f.button :submit, class: "btn-primary col-md-12" %>
  </div>
<% end %>
</div>
<div class="nested-fields">
  <div class="row">
    <div class="col-md-4"><%= f.input :name %></div>
    <div class="col-md-4"><%= f.input :singfile %></div>
    <div class="col-md-4"><%= f.input :song_file, as: :file %></div>

    <%= link_to_remove_association "Remove Song", f, class: "btn btn-default btn-danger col-md-4"  %>
  </div>
</div>
全球信息栅格模型

class Gig < ActiveRecord::Base
    belongs_to :user
    has_many :songs

    accepts_nested_attributes_for :songs, :reject_if => :all_blank, :allow_destroy => true
end
class Song < ActiveRecord::Base
  belongs_to :song
  has_attached_file :song_file
end
class-Gig:all\u blank、:allow\u destroy=>true
结束
歌曲模式

class Gig < ActiveRecord::Base
    belongs_to :user
    has_many :songs

    accepts_nested_attributes_for :songs, :reject_if => :all_blank, :allow_destroy => true
end
class Song < ActiveRecord::Base
  belongs_to :song
  has_attached_file :song_file
end
classsong
我解决了这个问题,将
:html=>{:multipart=>true}
添加到

`<%= f.simple_fields_for(:songs), :html => { :multipart => true }` do |song| %>
   <%= render 'song_fields', :f => song %>
 <% end %>`
`{:multipart=>true}`do|song |%>
歌曲%>
`

我解决了这个问题,将
:html=>{:multipart=>true}
添加到

`<%= f.simple_fields_for(:songs), :html => { :multipart => true }` do |song| %>
   <%= render 'song_fields', :f => song %>
 <% end %>`
`{:multipart=>true}`do|song |%>
歌曲%>
`

请在提交表单时发布生成的参数散列。我假设无论您是否在测试中提供了文件,您都会看到这种行为?@Pavan我认为没有生成任何内容。。。一旦我将文件上传字段放入表单中,“提交”就停止工作。我也刚刚检查过,只有在我尝试附加文件时,“提交”按钮才会停止工作。请在提交表单时发布生成的参数散列。我假设无论您是否在测试中提供了文件,您都会看到这种行为?@Pavan我认为没有生成任何内容。。。一旦我将文件上传字段放入表单中,“提交”就停止工作。我也刚刚检查过,只有在我尝试附加文件时,“提交”按钮才会停止工作。请在提交表单时发布生成的参数散列。我假设无论您是否在测试中提供了文件,您都会看到这种行为?@Pavan我认为没有生成任何内容。。。一旦我将文件上传字段放入表单中,“提交”就停止工作。我也刚刚检查过,只有在我尝试附加文件时,“提交”按钮才会停止工作。