2012-12-19 59 views
2

我在我的Rails應用程序中使用Paperclip gem來進行圖片上傳。但在意見中,沒有圖像。丟失圖像的路徑是http://localhost:3000/assets/。 下面是代碼:來自image_tag和Rails回形針的錯誤地址

<div class="advert_images"> 
    Фото: <br> 
    <% if @advertising.image.url %> 
    <%= image_tag(@advertising.image) %>  
    <% end %> 
    <br> 
    Розташування на карті: <br> 
    <% if @advertising.map.url(:normal) %> 
    <%= image_tag(@advertising.map.url(:normal)) %> 
    <% end %> 
</div> 

奇怪的是,當放在代碼<%= @advertising.image.url %>顯示我現有圖像的正確路徑(例如/system/adverts/images/000/001/408/original/luxot.gif?1355951576)。

模型:

# -*- encoding : utf-8 -*- 
class Advert < ActiveRecord::Base 
attr_accessible :adress, :category, :city, :desc, :map_path, :name, :image_path, :map,  :image 
has_attached_file :map, :styles => {:normal => "350x265", :thumb => "250x165"} 
has_attached_file :image, :styles => {:normal => "350x265", :thumb => "250x165"} 

    validates :name, :length => {:in => 2..20}, :presence => true 
    validates :category,       :presence => true 
    validates :city,        :presence => true 
    validates :adress,       :presence => true 


scope :by_city, lambda {|city| where("city = ?", city)} 
scope :by_category, lambda {|category| where("category = ?", category)} 

end 
+0

hm。您是否曾嘗試在瀏覽器中輸入網址0.0.0.0:3000/system/adverts/images/000/001/408/original/luxot.gif? –

+0

是的,這是正確的 – DarkSun

+0

以及如何將<%= image_tag(@ advertising.map.url(:normal))%>呈現爲HTML? –

回答

2

找到了解決辦法。 我改變了默認路徑,其中紙夾存儲圖像。

has_attached_file :image, 
       :url => "/assets/:id/:style/:basename.:extension", 
       :path => 
       ":rails_root/app/assets/images/:id/:style/:basename.:extension"