1

私はRailsアプリを持っていて、リモートフォームを作成しようとしていますが、これまでのところうまくいきません..誰かが私がここで間違っていることを教えてもらえますか:

だからモデル:

class Media < ActiveRecord::Base
  attr_accessible :galaxy, :title, :rss_url, :avatar
  has_many :stories
  has_many :plots, :through => :stories




class Story < ActiveRecord::Base
  attr_accessible :content, :galaxy, :title
  validates_uniqueness_of :content
  belongs_to :media
  has_many :plots




class Plot < ActiveRecord::Base
  belongs_to :plotable, :polymorphic => true
  has_many :plots, :as => :plotable
  has_many :soundtracks, :as => :soundtrackable, :dependent => :destroy
  accepts_nested_attributes_for :soundtracks, :allow_destroy => true

したがって、app/views/medias/show.html.erb で表示::

  <% @media.stories.each do |s| %>
   <%= form_for :plot, :remote => true, :html => { :id => 'pl_form' } do |f| %>
    <%= f.fields_for :soundtracks do |soundtrack_fields| %> 
       <%= soundtrack_fields.file_field :soundtrack %>
     <% end %>
    <%= text_field_tag :name, s.content, :style =>"display:none" %>
    <%= f.submit %>
   <% end %> 

アプリ/ビュー/プロット/create.js.erb

var el = $('#new_pl');
  // We could also render a partial to display the plot here
  $('#plots').append("<%= escape_javascript( 
      simple_format( @plot.body ) 
    ) %>");
  el.find('input:text,textarea').val('');
  el.find('.errors').empty();
<% end %>

コントローラは標準です。

4

1 に答える 1

0

フォームに multipart true を追加します

 <%= form_for :plot, :remote => true, :html => { :id => 'pl_form', :multipart => true } do |f| %>

W3C のマルチパート

ファイル、非 ASCII データ、およびバイナリ データを含むフォームを送信するには、コンテンツ タイプ「multipart/form-data」を使用する必要があります。

于 2012-06-23T12:04:32.437 に答える