2012-06-20 53 views
1

我有一個Rails應用程序,並試圖使遠程形式,到目前爲止,這是不是真的工作了..有人可以指向我,我做錯了什麼在這裏:帶回形針的遠程窗體在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 

所以查看應用程序/視圖/媒體/ 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 %> 

控制器是標準..

+0

什麼是不工作? – Salil

回答

0

從W3C

到窗體

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

Multipart添加多真實的內容類型 「的multipart/form-data的」 應該用於提交形式的包含文件,非ASCII數據和二進制數據