0

上传图像时,回形针正在保存带有扩展名的文件。我正在使用 ActiveRecord

photo.rb(模型):

require "sinatra"

class Photo < ActiveRecord::Base
    include Paperclip::Glue

    attr_accessible :image

    has_attached_file :image,
        :styles => {
            :small => "100x100#",
            :medium => "500x300"
        },
        :path => "#{settings.root}/public/system/:class/:attachment/:attachment/:id_partition/:style/:filename"
end

照片.rb(控制器):

post "/photos/?" do
        params[:photo][:image] = params[:photo][:image][:tempfile] if params[:photo][:image]
        @photo = Photo.new(params[:photo])
        if @photo.save
            { :status => "OK"}.to_json
        else
            { :status => "NOK"}.to_json
        end
    end
4

0 回答 0