我在 Rails 应用程序中使用 Paperclip gem 来上传图片。但在视图中,没有图像。丢失图像的路径是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