我使用tinymce-rails-image-upload上传与回形针图像上传图像时(以下this演示应用程序)。当我尝试上传图片时,我收到'无法通过参数'的提醒,图片无法上传。上传模式显示 '得到了服务器坏响应':未经许可的参数与TinyMCE的
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)
这里的控制器:
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
,问题型号:
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"] %>
它的确定不会允许一些参数,所以'不允许的参数:UTF8,authenticity_token'是一个提醒,也不例外。我建议你记录什么是'问题'模型实例错误: 'logger.debug question.errors.full_messages(after question = Question.create params.permit(:file,:alt,:hint)line)' – 2015-02-08 05:33:20
啊,谢谢,这表明了问题。我正在验证问题主体的存在,它是空白的。但是,现在没有错误显示,但图像仍未上传(使用新输出编辑问题)。 – user2759575 2015-02-08 18:46:46
我想补充':HTML => {:多=>真}'选项的形式: <%= simple_form_for [@comment,Question.new]:HTML => {:多=>真}做| F | %> 我认为问题出在这里: 在'file_content_type'列上插入字符串类型的二进制数据 也许我的建议可以解决这个问题。 – 2015-02-08 19:46:54