我在我的Rails 3示例应用程序上使用CarrierWave。我想,当用户提交一个无效的URL空的,或者不是图像来验证远程位置上传,所以我没有得到标准错误异常:我该怎么做:使用CarrierWave进行远程位置验证?
CarrierWave::DownloadError in ImageController#create
trying to download a file which is not served over HTTP
这是我的模型:
class Painting < ActiveRecord::Base
attr_accessible :gallery_id, :name, :image, :remote_image_url
belongs_to :gallery
mount_uploader :image, ImageUploader
validates :name, :presence => true,
:length => { :minimum => 5, :maximum => 100 }
validates :image, :presence => true
end
这是我的控制器:
class PaintingsController < ApplicationController
def new
@painting = Painting.new(:gallery_id => params[:gallery_id])
end
def create
@painting = Painting.new(params[:painting])
if @painting.save
flash[:notice] = "Successfully created painting."
redirect_to @painting.gallery
else
render :action => 'new'
end
end
def edit
@painting = Painting.find(params[:id])
end
def update
@painting = Painting.find(params[:id])
if @painting.update_attributes(params[:painting])
flash[:notice] = "Successfully updated painting."
redirect_to @painting.gallery
else
render :action => 'edit'
end
end
def destroy
@painting = Painting.find(params[:id])
@painting.destroy
flash[:notice] = "Successfully destroyed painting."
redirect_to @painting.gallery
end
end
我真的不知道该如何处理这个问题,所以任何见解将是巨大的。
我不确定是否最好的方法去创建:在模型中验证:remote_image_url,并有一个正则表达式来验证它是否是一个URL和图像。 – 2011-05-16 02:28:51