Rails Paperclip预编译错误

时间:2012-10-24 13:57:23

标签: ruby-on-rails paperclip precompile

我修改了这样的Paperclip-using模型:

class UsersPicture < ActiveRecord::Base
attr_accessible :user_id, :users_picture_id, :photo
belongs_to :user
has_attached_file :photo,
   :url => "users_pictures/:attachment/:id/:basename.:extension",
   :path => ":rails_root/users_pictures/:attachment/:id/:basename.:extension"

before_create :rename_file_name

def rename_file_name
  extension = File.extname(photo_file_name).downcase
  filename = File.basename(photo_file_name).downcase
  timestamp = Time.now.to_i
  name = Digest::MD5.hexdigest("#{filename}")
  self.photo.instance_write(:file_name, "#{name}_#{timestamp}#{extension}")
end
end

在我插入before_create方法之前,一切都很好。 但现在我的日志说:

ActionView::Template::Error (users_pictures/photos/88/8b7474622cf5bbc140ed7defe1ae76a8_1351088476.jpeg isn't precompiled):
8: <p>
9:   <b>Users picture file:</b>
10:  <% if @users_picture.photo.exists? then %>
11:             <%= image_tag @users_picture.photo.url %>
12:         <% end %>
13: </p>
14: 
app/views/users_pictures/show.html.erb:11:in `_app_views_users_pictures_show_html_erb__597237708__324410398'
app/controllers/users_pictures_controller.rb:18:in `show'

我正在寻找解决方案但总是记得使用“image_tag”。但我目前正在使用它? 当然索引工作正常,但show方法不会:/ 我能改变什么? 编辑:当我删除image_tag时,我得到: users_pictures / photos / 88 / 8b7474622cf5bbc140ed7defe1ae76a8_1351088476.jpeg

这也是正确的道路。

1 个答案:

答案 0 :(得分:0)

尝试使用/

为图像路径添加前缀
<%= image_tag "/" + @users_picture.photo.url %>

来自https://stackoverflow.com/a/11318133/418819