2013-10-11 53 views
1

即將保存用回形針上傳到特定路徑的圖像。 我想要保存在應用程序/資產/圖像目錄中的應用程序的ruby on rails應用程序中的圖像,但他們似乎並沒有去那裏回形針圖片未保存在我設置的路徑中

這是什麼路徑看起來像在config/environments/development.rb

config.paperclip_defaults = { 
:url => ":rails_root/app/assets/images/:attachment/:id/:style/:filename",  
:path => "/:class/:attachment/:id/:style/:basename.:extension" 
} 

我真的很感激任何建議或幫助,您可以給我,如果你想了解更多的信息,我會把它那麼快,我可以。

這裏是DEF從展示如何創建圖像的product_images它裏面創建和保存

def create 
@product_image = ProductImage.new(params[:product_image]) 
@product = @product_image.product 

if @product_image.save 
    @product.product_image_id = @product_image.id 
    @product.save 

    redirect_to @product_image, notice: 'Product image was successfully created.'   
else 
    render :template => "products/edit"  
end  
end 

回答

0

在你的模型,你所訪問的曲別針,把這個代碼,而不是development.rb文件。

has_attached_file :model_name, 
:path => ":attachment/:id/:style/:basename.:extension" 
+0

我在圖像目錄中看不到任何更改。 我將在這裏添加def create p [控制器的藝術,以便您可以查看圖像是否正確保存。它作爲product_images belongs_to產品有點複雜。 –

+1

我只是重新閱讀你的問題並思考它。 Rails將圖像放入公用文件夾,因此如果您想要保存圖像,可以在公用文件夾內創建一個圖像文件夾並將其保存在那裏。出於這個原因,我使用亞馬遜s3。 – coletrain