我修改了我的回形针使用模型,如下所示:
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
而这也是正确的道路。