【问题标题】:Bad response from server after tinymce image uploadtinymce 图像上传后服务器响应错误
【发布时间】:2015-02-15 09:17:55
【问题描述】:

我正在尝试使用回形针和tinymce-rails-image-upload 上传图片,并遵循this 演示。我在问题模型(属于 cmets)中上传图像。上传时,我收到“服务器响应错误”消息,并且图像未显示在编辑器中,但它确实创建了一个新问题。

这是我上传后的日志:

Processing by TinymceAssetsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"auth token", "hint"=>"", "file"=>#<ActionDispatch::Http::UploadedFile:0x000001025a2780   @tempfile=#   <File:/var/folders/t4/86vsrmds42j84r36kwpng7k00000gn/T/RackMultipart20150207-  12522-9rj6xq>, @original_filename="applecash.jpg", @content_type="image/jpeg",   @headers="Content-Disposition: form-data; name=\"file\";   filename=\"applecash.jpg\"\r\nContent-Type: image/jpeg\r\n">, "alt"=>""}
Command :: identify -format '%wx%h,%[exif:orientation]' '/var/folders/t4/86vsrmds42j84r36kwpng7k00000gn/T/RackMultipart20150207-12522-9rj6xq[0]' 2>/dev/null
Unpermitted parameters: utf8, authenticity_token
(0.1ms)  begin transaction
Question Load (0.5ms)  SELECT "questions".* FROM "questions" WHERE (questions.position IS NOT NULL) AND (1 = 1) ORDER BY questions.position DESC    LIMIT 1
Binary data inserted for `string` type on column `file_content_type`
SQL (0.8ms)  INSERT INTO "questions" ("created_at", "file_content_type", "file_file_name", "file_file_size", "file_updated_at", "position", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?)  [["created_at", Sun, 08 Feb 2015 18:35:07 UTC +00:00], ["file_content_type", "image/jpeg"], ["file_file_name", "timcook.jpg"], ["file_file_size", 120040], ["file_updated_at", Sun, 08 Feb 2015 18:35:07 UTC +00:00], ["position", 9], ["updated_at", Sun, 08 Feb 2015 18:35:07 UTC +00:00]]
(7.3ms)  commit transaction
Completed 200 OK in 68ms (Views: 0.6ms | ActiveRecord: 8.7ms)

这是 tinymce 控制器:

class TinymceAssetsController < ApplicationController
respond_to :json

def create
  geometry = Paperclip::Geometry.from_file params[:file]
  question = Question.create params.permit(:file, :alt, :hint)

 render json: {
   question: {
   url:    question.file.url,
   height: geometry.height.to_i,
   width:  geometry.width.to_i
  }
 }, layout: false, content_type: "text/html"

 end
end

问题控制器创建操作看起来像这样(我是否将@comment 和其他参数添加到tinymce 控制器?):

def create
  @comment = Comment.find(params[:comment_id])
  @question = @comment.questions.new(question_params)
end
...
def question_params
  params.require(:question).permit(:body, :comment_id, :user_id, :file, :position)
end

问题模型:

class Question < ActiveRecord::Base
  has_attached_file :file
end

和编辑器视图:

<%= simple_form_for [@comment, Question.new] do |f| %>    
<%= f.text_area :body, :class => "tinymce", :rows => 10, :cols => 60 %>
<% end %>
<%= tinymce plugins: ["uploadimage"] %>

我很困惑为什么它为每个上传的图像创建一个新问题,以及仍然导致“错误响应”错误的原因。

【问题讨论】:

  • 您没有收到类似于 BAD ADDRESS!! #&lt;Excon::Errors::SocketError: Bad address&gt; 的错误
  • 不,我看不到地址错误。

标签: ruby-on-rails


【解决方案1】:

似乎 tinymce-rails-imageupload 需要“图像”来响应上传的文件

render json: {
   image: {
   url:    question.file.url,
   height: geometry.height.to_i,
   width:  geometry.width.to_i
  }
 }, layout: false, content_type: "text/html"

【讨论】:

  • source 中的第 144 和 177 行
  • 呃,就是这样。谢谢!
猜你喜欢
  • 2015-02-17
  • 1970-01-01
  • 2020-12-04
  • 1970-01-01
  • 1970-01-01
  • 2019-01-07
  • 1970-01-01
  • 2017-04-27
  • 1970-01-01
相关资源
最近更新 更多