2

RailsアプリでPaperclipgemを使用して画像をアップロードしています。しかし、ビューでは、画像はありません。欠落している画像のパスはですhttp://localhost:3000/assets/。コードは次のとおりです。

<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
4

1 に答える 1

2

解決策を見つけました。ペーパークリップが画像を保存するデフォルトのパスを変更しました。

  has_attached_file :image,
                :url => "/assets/:id/:style/:basename.:extension",
                :path =>  
                ":rails_root/app/assets/images/:id/:style/:basename.:extension"
于 2012-12-20T19:27:05.610 に答える