【问题标题】:carrierwave fog storage载波雾存储
【发布时间】:2013-02-21 02:23:53
【问题描述】:

我只是不知道该怎么做。我需要获取没有文件名的 S3 路径 https://testphotobucket.s3.amazonaws.com/uploads/51237a37ff770df332000007/

不是这样的 https://testphotobucket.s3.amazonaws.com/uploads/51237a37ff770df332000007/tiger.jpg

但我不断收到此错误。 未定义的方法gallery_photo_path' for #<Gallery:0x007f94f4658778> undefined methodgallery_photo_http_url' 用于#

如果我使用雾作为存储,我该如何获取路径?

谢谢。下面是我的代码sn-p。

# models/gallery.rb
class Gallery

  include Mongoid::Document        

  mount_uploader :gallery_photo, PhotoUploader

# uploaders/photo_uploader.rb
class PhotoUploader < CarrierWave::Uploader::Base

  storage :fog

# views/galleries/show.html.erb
<%= image_tag @gallery.gallery_photo_url.to_s %>
path **<%= @gallery.gallery_photo_path.to_s %>**   <--- not working
httppath **<%= @gallery.gallery_photo_http_url.to_s %>** <--- not working

# the error:
undefined method `gallery_photo_path' for #<Gallery:0x007f94f4658778>
undefined method `gallery_photo_http_url' for #<Gallery:0x007f94f46431e8>

【问题讨论】:

    标签: url path amazon-s3 carrierwave fog


    【解决方案1】:

    您所要求的并非内置于运营商波中。你可能应该把它放在一个助手中:

    def uri_dirname(uri_string)
      uri = URI.parse(uri_string)
      uri.path = File.dirname(uri.path)
      uri.to_s
    end
    

    然后在你看来你可以使用:

    uri_dirname(@gallery.gallery_photo.uri)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-14
      • 2012-03-16
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多