Ruby on rails 使用tinymce上载图像时未经允许的参数

Ruby on rails 使用tinymce上载图像时未经允许的参数,ruby-on-rails,Ruby On Rails,我用回形针上传图片的演示程序如下。当我试图上传一个图像时,我会收到一个“umpermitted parameters”提醒,而图像不会上传。上载模式显示“从服务器收到错误响应”: Processing by TinymceAssetsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"auth token", "hint"=>"", "file"=>#<ActionDi

我用回形针上传图片的演示程序如下。当我试图上传一个图像时,我会收到一个“umpermitted parameters”提醒,而图像不会上传。上载模式显示“从服务器收到错误响应”:

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"] %>

可能是错误的,但您有以下几点:

 question = Question.create params.permit(:file, :alt, :hint)
我想你只要把它写成这样就行了:

 question = Question.create params.permit(:file, :alt, :hint, :utf8, :authenticity_token)
错误很明显。您不允许使用这些参数。但它们确实存在。你明确允许其他三个在那里,所以我想你必须允许这两个额外的


这是我的猜测,我坚持认为:。

不允许某些参数是可以的,所以不允许的参数:utf8,authenticity\u token是一个提醒,而不是一个例外。我建议您记录什么是问题模型实例错误:

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

嗯,猜对了,但这给了我一个“unknown attribute:utf8”和“unknown attribute:authenticity\u token”错误。这意味着数据库中不存在utf8和authenticity\u token列,我怀疑,我们知道这一点,因为这是一个教程,他们没有。现在,我假设如果您添加可以保存这些参数的字段,这将起作用,但这似乎是一个过时的教程,否则我就完蛋了:。我试过了。是tinymce控制器中的这个新创建操作把事情搞砸了,因为之前创建的问题没有错误。好吧,我会继续玩下去。无论如何,感谢您的帮助:不允许某些参数是可以的,所以不允许的参数:utf8,authenticity\u token是一个提醒,而不是一个例外。我建议您记录什么是问题模型实例错误:logger.debug question.errors.full_messages after question=question.create params.permit:file,:alt,:hint lineAh,谢谢,这显示了问题。我正在确认问题主体的存在,但它是空白的。但是,现在没有显示错误,但是图像仍然没有上传带有新输出的已编辑问题。我将在表单中添加:html=>{:multipart=>true}选项:{:multipart=>true}do | f |%>我认为问题在于:在列文件(content)type上插入字符串类型的二进制数据,也许我的建议可以解决这个问题。Hmm,不走运。我对整件事有点困惑,我想我会问一个新的,更一般的问题。如果你想发布你的原始评论作为答案,我会接受它,因为它确实解决了我最初的问题。感谢您的帮助: