回形针图像未保存在我设置的路径中 [英] paperclip images not saving in the path i've set up

查看:72
本文介绍了回形针图像未保存在我设置的路径中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在尝试将使用回形针上传的图像保存到特定路径. 我希望将图像保存在Rails应用程序的ruby中的app/assets/image dir中,但它们似乎没有进入

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,显示了如何创建图像并保存它

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆