我在一个花式盒子里有这个表格:
<%= simple_form_for(@message, :remote => true, :html => {:multipart => true}, :url => { :controller => "users/messages", :action => "create"} ) do |f| %>
<%= f.error_notification %>
<%= f.input :subject, :input_html => { :maxlength => 500} %>
<%= f.input :message_image, :as => :file %>
<%= f.button :submit, t('.send_message'), :class => 'btn-large btn-primary', "data-disable-with" => t('.send_message'), :confirm => t('.sure_send_message') %>
<% end %>
这是我的创建操作:
def create
@message = Message.new(params[:message])
respond_to do |format|
if @message.save
format.js { render :partial => "users/messages/templates/sent_by_user/create" }
else
format.js { render :partial => "users/messages/templates/sent_by_user/nosave" }
end
end
end
如果我不尝试上传图片,文件create.js.erb
或文件工作正常nosave.js.erb
如果我尝试上传图像,则不会呈现此文件。
但是在我的日志中我可以看到:
Processing by Users::MessagesController#create as JS
Parameters: {"message"=>{"message_image"=>#<ActionDispatch::Http::UploadedFile:0xf7a85c8 @original_filename="cara_enfadada.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"message[message_image]\"; filename=\"cara_enfadada.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File:/tmp/RackMultipart20121015-21710-6oxtn2>>, "subject"=>"estrella de neutronessssssssssss"}, "commit"=>"Enviar mensaje", "utf8"=>"✓", "authenticity_token"=>"mfSsl0HafWoW86YiO2Hj7zMepAITZlHHBtUqW0wzubU=", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01", "locale"=>"es"}
和
Rendered users/messages/templates/sent_by_user/_nosave.js.erb (0.2ms)
Completed 200 OK in 498ms (Views: 1.5ms | Solr: 0.0ms)
在 google chrome 控制台上,我收到下一个警报:
Resource interpreted as Document but transferred with MIME type text/javascript:
我正在使用 remotipart gem 但我没有找到错误...错误在哪里?谢谢