无法使用回形针将符号转换为字符串

时间:2014-11-11 02:17:08

标签: ruby-on-rails ruby paperclip

我是铁轨上的红宝石的新手,我正在尝试使用回形针来拖放图像。当我运行我的应用程序时,我有一个错误:

 Started POST "/uploads" for 127.0.0.1 at 2014-11-11 08:59:54 +0700
    Processing by UploadsController#create as JSON
      Parameters: {"utf8"=>"✓", "authenticity_token"=>"EXaUGMxPQt6otEUvPAd97IHEq61lYDmmHElxSCpyGp0=", "upload"=>{"image"=>#<ActionDispatch::Http::UploadedFile:0x33f55c8 @original_filename="Chrysanthemum.jpg", @content_type="image/jpeg", @headers="Content-Disposition: form-data; name=\"upload[image]\"; filename=\"Chrysanthemum.jpg\"\r\nContent-Type: image/jpeg\r\n", @tempfile=#<File...AppData/Local/Temp/RackMultipart20141111-1960-9xj2rp>>}}
    Completed 500 Internal Server Error in 2.0ms

    TypeError (can't convert Symbol into String):
      app/controllers/uploads_controller.rb:17:in `upload_params'
      app/controllers/uploads_controller.rb:7:in `create

Upload_controller:

class UploadsController < ApplicationController
  def new
    @upload = Upload.new
  end

  def create
    @upload = Upload.create(upload_params)
    if @upload.save
      render json: { message: "success" }, :status => 200
    else
      render json: { error: @upload.errors.full_messages.join(',')}, :status => 400
    end
  end

   private
  def upload_params
    params.require(:upload).permit(:image)
  end
end

Upload_model:

class Upload < ActiveRecord::Base
  attr_accessible :image
  has_attached_file :image, :styles => { :medium => "300x300>",:thumb => "100x100>" }

  validates_attachment  :image, 
        :presence => true,
        :content_type => { :content_type => /\Aimage\/.*\Z/ },
        :size => { :less_than => 1.megabyte }
end

upload.html

<%= form_for(@upload, html: { multipart: true, class: "dropzone"}) do |f|  %>
        <div class="fallback">
            <%= f.file_field :image %>
            <br>
            <%= f.submit "Upload" %>
        </div>
        <% end %>

也许,问题是我不使用“strong_parameters”,但是当我添加gem“strong_parameters”时,它不起作用。我不知道如何解决这个问题:(救救我!

0 个答案:

没有答案