2015-02-07 2 views
0

tinymce-rails-image-upload을 사용하여 클립으로 이미지를 업로드하고 있습니다 (this demo-app 다음). 이미지를 업로드하려고 할 때 'umpermitted parameters'알림이 표시되고 이미지가 업로드되지 않습니다.주석으로 이미지를 업로드 할 때 허용되지 않는 매개 변수

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 

하고 뷰 :

다음
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) 

컨트롤러입니다 : 업로드 모달 쇼 '서버에서 잘못된 응답을 얻었다'
<%= 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' 미리 알림이 아닌 예외입니다. 'question' 모델 인스턴스 오류가 무엇인지 기록해 보시기 바랍니다 : 'logger.debug question.errors.full_messages (질문 후 = question.create params.permit (: file, : alt, : 힌트) 행)' –

+0

Ah , 고맙습니다, 그게 문제를 보여줍니다. 나는 질문 본문의 존재를 확인하고 있었고 그것은 공백이었다. 그러나 이제 오류는 표시되지 않지만 이미지는 여전히 업로드되지 않습니다 (새 출력이있는 편집 된 질문). – user2759575

+0

<% = simple_form_for [@comment, Question.new], : html => {: multipart => true} 형식에': html => {: multipart => true}'옵션을 추가합니다. f | %> 여기에 문제가 있다고 생각합니다 : 'file_content_type' 열에'string '유형의 이진 데이터가 삽입되었습니다. 그리고 아마도 제 제안으로 해결할 수 있습니다. –

답변

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

+0

글쎄, 그것은 utf8과 authenticity_token 컬럼이 데이터베이스에 존재하지 않는다는 것을 의미합니다. 이것은 우리가 알고있는 것은 튜토리얼이고 거기에 없었기 때문입니다. 자, 당신이 그 매개 변수를 저장할 수있는 필드를 추가하면 이것이 작동 할 것이라고 추측합니다. 그러나 오래된 튜토리얼처럼 보입니다. 나는 노력했다. – Art

+0

질문은 이전에 아무런 오류없이 생성 되었기 때문에 음향 제어기에 새로운 동작을 만들어 냈습니다. 좋아, 나는 그걸 가지고 놀고있다. 어쨌든 도움을 주셔서 감사합니다 :) – user2759575

관련 문제