我的heroku资产有什么问题:汇编?

时间:2015-06-03 22:54:45

标签: ruby-on-rails ruby heroku asset-pipeline

我正在尝试将图像插入到邮件程序中,所有内容都在本地运行,但heroku在其服务器上看不到图像,尽管我应该按照推送和预编译的方式进行操作。代码如下;

user_mailer.rb

def welcome_email(user)
    @user = user
    attachments.inline['my_logo_sml.png'] = File.read('app/assets/images/my_logo_sml.png')
    mail(to: @user.email, subject: 'Welcome to Mybiz')
end

welcome_email.html.erb

<td class="six sub-columns header_logo">
    <%= image_tag attachments["my_logo_sml.png"].url -%>
</td>

的Gemfile

gem 'rails_12factor', group: :production 

app/assets/images/my_logo_sml.png显然存在,并在当地通过管道。

我已多次运行RAILS_ENV=production bundle exec rake assets:precompile,我已多次heroku restart次。

Heroku日志:

2015-06-03T22:38:50.824191+00:00 app[web.1]: Errno::ENOENT (No such file or directory @ rb_sysopen - app/assets/images/my_logo_sml.png)

我几个小时后不知疲倦地走来走去,有人能帮帮我吗?

更新

看了几个小时之后,我觉得这不是语法问题,而是某种资产预编译问题,如果有人发现任何错误,我已经将我的config / environments / production.rb代码复制到下面了:

Rails.application.configure do
  config.cache_classes = true
  config.eager_load = true
  config.consider_all_requests_local       = false
  config.action_controller.perform_caching = true
  config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present?
  config.assets.js_compressor = :uglifier
  config.assets.compile = true #concerned that this is the right thing to do?
  config.assets.digest = true
  config.log_level = :debug
  config.i18n.fallbacks = true
  config.active_support.deprecation = :notify
  config.log_formatter = ::Logger::Formatter.new
  config.active_record.dump_schema_after_migration = false
  config.action_mailer.asset_host = 'http://mysite.co'
  ActionMailer::Base.smtp_settings = {
    :address        => 'smtp.sendgrid.net',
    :port           => '587',
    :authentication => :plain,
    :user_name      => ENV['SENDGRID_USERNAME'],
    :password       => ENV['SENDGRID_PASSWORD'],
    :domain         => 'heroku.com',
    :enable_starttls_auto => true
  }
end

也许我可以清理所有已编译的资产并重新启动整个事情,有人可以建议如何做到这一点吗?

更新

我的问题的根源似乎是本地和slug资产编译之间的混淆。我跑了heroku run rake assets:clobber,这解决了我所有的问题。完全理解究竟发生了什么仍然无法实现,但运行上述内容并在config / environments / production.rb中使用config.assets.compile = true可以使一切正常工作,git push heroku它清楚地告诉我它正在运行rake assets:cleanrake assets:precompile都很好。视图中使用的语法是:

welcome_email.html.erb

<%= image_tag('my_logo_sml.png', alt: "My Logo Small")%>

我仍然不确定config.assets.compile = true是否是正确的事情,尽管它似乎解决了这个问题,但我想知道它是否最终会在多个场合编译资产?

2 个答案:

答案 0 :(得分:0)

按照@ user123的建议从Rails控制台读取文件,显示路径正确,文件在那里。尝试从Heroku运行控制台读取文件找不到该文件并提出相同的Errno::ENOENT no such file error奇怪的是,heroku正在主页中提供图像,我尝试加载如上所述在heroku控制台中,它无法找到它。

答案 1 :(得分:0)

我有类似的问题。我认为welcome_email.html.erb文件不能是.erb文件。有一个解决方法。您可以将图像放在网络上的某个位置,如亚马逊或图像共享服务,并使用链接作为源。

<img src='https://example.com'>