我使用以下表格:
<%= form_for(@document, :remote => true) do |f| %>
<%= f.label :asset, "Document to Upload" %><br />
<%= f.file_field :asset, :class => "behaves", "data-behave" => "passValueOnChange", "data-recipient" => "#campaign_document_name" %>
<%= f.label :name, :class => 'required' %><br />
<%= f.text_field :name, :required => true %>
<%= f.submit "Upload Document", :class => "button" %>
<% end %>
提交给以下控制器:
def create
@document = CampaignDocument.new(params[:campaign_document])
@campaign.documents << @document
respond_to do |format|
format.js
end
end
应返回以下create.js.erb
:
<%= remotipart_response do %>
<% unless @document.errors.any? %>
$('.tablewrapper').html( '<%= escape_javascript(render :partial=>'documents_table') %>' );
alertify.success("File Updloaded");
<% else %>
<% @document.errors.each do |attr, msg|%>
alertify.error("<%= msg %>",10000);
<% end %>
<% end %>
<% end %>
但响应包含在textare
标记中。这很奇怪:
<textarea data-type="text/javascript" response-code="200">
$('.tablewrapper').html('{code for HTML ommited for brevity}');
alertify.success("File Updloaded");
</textarea>
注意的 其他类似风格的AJAX函数在同一个安装中的行为并不是这样的。