1
我有一個的fancybox盒內這種形式:js.erb文件沒有解僱了
<%= 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)
谷歌瀏覽器的控制檯我得到下一個警報:
Resource interpreted as Document but transferred with MIME type text/javascript:
我使用remotipart寶石,但我沒有找到錯誤... 錯誤在哪裏? 謝謝
非常感謝您! – hyperrjas