0

Carrierwave で動作するアプリを入手しました。保存された画像の URL へのパスを提供する @product.image.url のようなこともできます。

しかし、products#show (つまり、http://localhost:3000/products/1.xml ) を参照すると、画像を除くすべてが正しく表示されます。

コンソールでは、@product.image.url は次を返します。

"https://bucket_name.s3.amazonaws.com/uploads/products/2/prod1.jpg" 

画像には名前と拡張子のみが表示されます。パスではありません。これは正常ですか?

たとえば、xml は次のようになります。

product>
  <attachment>prod1.jpg</attachment>
  <cached-slug>adsfsadf</cached-slug>
  <category-id type="integer">1</category-id>
  <company-id type="integer">1</company-id>
  <created-at type="datetime">2011-05-10T05:10:35Z</created-at>
  <description>description here</description>
  ...
4

1 に答える 1

1

うん、Carrierwave は URL を動的に (メソッド内で) 生成していると思うので、計算方法を変更またはオーバーライドできます。

format.xml  { render :xml => @product.to_xml(:include => {:attachment => {:only => :url}}) }

編集:私のために働く:

format.xml  { render :xml => @product.to_xml(:except => :attachment, :methods => :attachment_url) }
于 2011-05-11T12:32:30.073 に答える