paperclip images not saving in the path i've set up

一笑奈何 提交于 2019-12-11 05:04:40

问题


im tring to save the images I upload with paperclip to a specific path. I would like the Images to be saved in app/assets/image dir in the ruby on rails application, but they don't seem to go in there

this is what the path looks like in the config/environments/development.rb

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

I really appreciate any advice or help you can give me, if you would like more info I'll put it up as quick as I can.

here is the def create from the product_images showing how I create an image and save it

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

回答1:


In your model that you're accessing paperclip, place this code inside of it rather than the development.rb file.

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


来源:https://stackoverflow.com/questions/19321473/paperclip-images-not-saving-in-the-path-ive-set-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!