2015-02-07 48 views
0

我使用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"] %> 
+0

它的确定不会允许一些参数,所以'不允许的参数: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

+0

啊,谢谢,这表明了问题。我正在验证问题主体的存在,它是空白的。但是,现在没有错误显示,但图像仍未上传(使用新输出编辑问题)。 – user2759575 2015-02-08 18:46:46

+0

我想补充':HTML => {:多=>真}'选项的形式: <%= simple_form_for [@comment,Question.new]:HTML => {:多=>真}做| F | %> 我认为问题出在这里: 在'file_content_type'列上插入字符串类型的二进制数据 也许我的建议可以解决这个问题。 – 2015-02-08 19:46:54

回答

0

它的确定不会允许一些参数,所以不允许的参数:utf8, authenticity_token是一个提醒,也不例外。我建议你登录什么问题模型实例错误:

question = Question.create params.permit(:file, :alt, :hint) 
logger.debug question.errors.full_messages 
0

可能是错的,但,您具备以下条件:

question = Question.create params.permit(:file, :alt, :hint) 

我想你会只是使这样写的,它会工作:

question = Question.create params.permit(:file, :alt, :hint, :utf8, :authenticity_token) 

的错误是明显的。你没有允许这些参数。但它们存在。你明确允许其他三个人,所以我认为你必须允许这两个额外的。

这是我的猜测,我坚持它:)。

+0

嗯,有效的猜测,但这给了我一个'未知属性:utf8'和'未知属性:authenticity_token'错误。 – user2759575 2015-02-08 00:02:58

+0

那么,这意味着数据库中不存在utf8和authenticity_token列,我怀疑这是我们知道的,因为这是一个教程,并且他们没有。现在,我假设如果你添加可以容纳这些参数的字段,这将起作用,但是这看起来像是一个过时的教程,或者我正在关闭:)。我试过了。 – Art 2015-02-08 00:09:36

+0

嗯,这是tinymce控制器中的这个新的创建动作,它搞砸了,因为之前创建的问题没有错误。好吧,我会继续玩它。感谢您的帮助:) – user2759575 2015-02-08 00:39:13