【问题标题】:paperclip images not saving in the path i've set up回形针图像未保存在我设置的路径中
【发布时间】:2013-10-11 23:31:53
【问题描述】:

我想将我用回形针上传的图像保存到特定路径。 我希望将图像保存在 ruby​​ on rails 应用程序的 app/assets/image 目录中,但它们似乎没有进入那里

这是路径在 config/environments/development.rb 中的样子

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

非常感谢您能给我的任何建议或帮助,如果您想了解更多信息,我会尽快提供。

这里是来自 product_images 的 def create 展示了我如何创建图像并保存它

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

【问题讨论】:

    标签: ruby-on-rails url path paperclip


    【解决方案1】:

    在您访问回形针的模型中,将此代码放在其中,而不是放在 development.rb 文件中。

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

    【讨论】:

    • 我没有看到图像目录有任何变化。我将在此处添加控制器的 def create p[art,以便您查看图像是否正确保存。它有点复杂,因为 product_images belongs_to 产品。
    • 我刚刚重新阅读了您的问题并考虑了它。 Rails 将图像放入公用文件夹,因此如果您想保存图像,可以在公用文件夹中创建一个图像文件夹并将它们保存在那里。出于这个原因,我使用亚马逊 s3。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-27
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 2018-08-11
    相关资源
    最近更新 更多