我在我的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