2

我在目录中有一个class AvatarUploader < Carrierwave::Uploader::Base哪个商店的User头像public/uploads

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  version :main do
     process :resize_to_limit => [128, 128]
  end

我想在production启用资产预编译的模式下启动应用程序。除了头像之外的一切都很好。当我访问任何User个人资料时,我会得到:

Started GET "/users/1" for 127.0.0.1 at 2012-05-03 17:45:24 +0300
Processing by Users::UsersController#show as HTML
  Parameters: {"id"=>"1"}
  Rendered users/users/show.html.erb within layouts/application (2.5ms)
Completed 500 Internal Server Error in 16ms

ActionView::Template::Error ( isn't precompiled):
    87:                     <%= image_tag @user.avatar_url(:main).to_s %>
  app/views/users/users/show.html.erb:87:in `_app_views_users_users_show_html_erb___538221278131396366_28399560'

也许有一种方法可以关闭头像的预编译(因为它们可以在应用程序在生产环境中运行时重新上传)。请提供如何解决此问题的任何建议。谢谢。

4

1 回答 1

7

当 image_tag 收到一个空白字符串时,它会尝试从资产管道中获取资源并返回

“未预编译”

https://github.com/rails/rails/issues/3080

打印@user.avatar_url(:main).to_s以仔细检查

于 2012-05-03T15:06:20.727 回答