0
我修改了使用回形針模型是這樣的:Rails的回形針預編譯錯誤
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 /照片/ 88/8b7474622cf5bbc140ed7defe1ae76a8_1351088476.jpeg
,這也是正確的路徑。