回形针图像未保存在我设置的路径中 [英] paperclip images not saving in the path i've set up
问题描述
我想将我用回形针上传的图像保存到特定路径.我希望将图像保存在 ruby on rails 应用程序的 app/assets/image 目录中,但它们似乎没有进入
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
这是 config/environments/development.rb 中的路径
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.
这是来自 product_images 的 def create,显示了我如何创建图像并保存它
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
推荐答案
在您访问回形针的模型中,将此代码放在其中而不是 development.rb 文件中.
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"
这篇关于回形针图像未保存在我设置的路径中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!