2012-06-14 51 views
3

我有一个问题发生在只有在生产环境中,部署在heroku。heroku Errno :: ENOENT(没有这样的文件或目录 -/assets /)

Heroku的日志说:

class Notifier < ActionMailer::Base 
    default from: "..." 

    def new_user_creation(user) 
    @user = user 
    @url= "http://stark-blabla-345.herokuapp.com/users/ 
        #{user.create_digitally_signed_remember_token}/confirm" 
    mail to:user.email, subject: 'bla bla, complete the registration process' 

    end 

end 

具有以下templete new_user_creation.html.erb:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <title><%=t("confirm_account_creation")%></title> 
     <style type="text/css"> 
      body{ background:#f1f1ee; } 
     .title{font-size: 300%; font-family: Georgia, serif; font-weight:bold;} 
     .indented{margin-left:5%; padding:1%;} 
     </style> 
    </head> 

<body> 
    <table width="100%" id="background" border="0" cellpadding="0" cellspacing="0"> 
    <tr> 
     <td> 
     <img src="http://stark-blabla-345.herokuapp.com/assets/ 
      red_flower-a4105a7cc626711e8789b1c2b21777b6.png" 
      align="middle"> 
     <span class="title"><%=t("base_title")%></span> 
     </td> 
    </tr> 

    <tr> 
    <td> 
     <p class="indented"><%=t("confirm_account_creation")%><p> 
     <p class="indented"><a href="<%[email protected]%>">COMPLETE ACCOUNT CREATION PROCESS</a></p> 
    </td> 
    </tr> 


    </table> 

</body> 

</html> 
添加具有这些特征的梅勒组件发生后

[...] 
Parameters: {"utf8"=>"✓", 
      "authenticity_token"=>"...", 
      "users"=>{"name"=>"name", "email"=>"[email protected]", 
      "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, 
      "commit"=>"Join Us!"} 

Processing by UsersController#create as HTML 
Rendered notifier/new_user_creation.html.erb (0.7ms) 
heroku[router]: POST stark-blabla-345.herokuapp.com/users dyno=web.1 queue=0 wait=0ms 
service=333ms status=500 bytes=643 
Completed 500 Internal Server Error in 284ms 
app[web.1]: Errno::ENOENT (No such file or directory - /assets/):*** 
app[web.1]: app/controllers/users_controller.rb:13:in `create 

此错误

UsersController#create():

def create 
    @user = User.new(params[:users]) 
    if @user.save 
    Notifier.new_user_creation(@user).deliver 
    flash.now[:block] = t("users.create.created") 
    render "confirm_registration"  
    else 
    render 'new' 
    end  
end 

我的Gemfile:

source 'https://rubygems.org' 
ruby '1.9.3' 
gem 'rails', '3.2.6' 
gem "heroku" 
# Bundle edge Rails instead: 
# gem 'rails', :git => 'git://github.com/rails/rails.git' 
gem 'bootstrap-sass' 
gem 'jquery-rails' 
gem "paperclip", "2.7.0" # :git => "git://github.com/thoughtbot/paperclip.git" 
gem 'bcrypt-ruby', '3.0.1' 
gem 'nokogiri' 
gem 'premailer-rails3' 

group :assets do 
    gem 'sass-rails', '~> 3.2.3' 
    gem 'coffee-rails', '~> 3.2.1' 
    gem 'uglifier', '>= 1.0.3' 
end 

group :test,:development do 
    gem 'sqlite3' 
    gem 'rspec-rails','2.9.0' 
    gem 'execjs' 
    gem 'annotate', '~> 2.4.1.beta' 
end 

group :test do 
    gem 'spork' 
    gem 'cucumber-rails', require:false; 
    gem 'capybara' 
    gem 'database_cleaner' 
    gem 'factory_girl' 
    gem "launchy" 
end 

group :production do 
    gem 'pg' 
    gem 'thin' 
end 

production.rb有趣的部分:

MyApp::Application.configure do 
    config.action_mailer.default_url_options = 
    { host: "stark-blabla-345.herokuapp.com" } 
    config.action_mailer.raise_delivery_errors = false # the same with true 
    config.action_mailer.delivery_method = :smtp 
    config.action_mailer.default :charset => "utf-8" 

    config.action_mailer.smtp_settings = { 
    address: "smtp.gmail.com", 
    port: 587, 
    domain: "stark-blabla-345.herokuapp.com", 
    authentication: "plain", 
    enable_starttls_auto: true, 
    user_name: ENV["GMAIL_USERNAME"], 
    password: ENV["GMAIL_PASSWORD"] 
    } 

end 
+0

在$ RAILS /资产是通常的内容:图像,样式表和javascripts。也许也是有趣的production.rb: –

+0

它也在我的开发和测试中发生。 – KendallB

回答

0

是否使用了premailer-rails3宝石?我发现版本1.2.0导致了这个完全相同的问题。降级到1.1.0就修正了它。希望有所帮助!

+0

谢谢KendallB!是的,其实我只是使用premailer 1.7.3。降级到1.1.0也适用于我。 –

+0

@StenKaRazin,如果它对你有效,你应该接受和upvote这个答案。 (我有同样的问题,所以确认这是完整的解决方案将是有用的。):) – thewillcole

+0

这已在'master'分支中修复:https://github.com/fphilipe/premailer-rails3 /问题/ 41 – KendallB

3

这不是一个只有英雄的问题。当email.css不存在或(从premailer-rails 1.3.x开始)内联style标签does not exist时抛出此异常。

解决方案是将email.css添加到您的资产文件夹或将空的<style type="text/css"> </style>添加到您的电子邮件HTML。

3

一直在努力与此数小时,并认为我会加入我的解决方案,为您的利益。

使用premailer-Rails3中(1.3.1)

我想我的电子邮件CSS相匹配的自举造型,所以我想一个懒惰的方法是简单地使用<%= stylesheet_link_tag "application", :media => "all" %>然而,这将导致找不到/资产/问题。

所以最后我做了以下内容:

  1. 需要从我application.css,这是很好的做法反正删除*= require_tree,并要求主css文件
*= require_self 
*= require <MyMainSiteCSS> 
*/ 
  1. 创建app/stylesheets/email.css与以下
@import "bootstrap"; 
@import "bootstrap-responsive"; 
  1. 改变了我的电子邮件视图的头是:
<head> 
    <link href="email.css" media="all" rel="stylesheet" type="text/css"> 
</head> 

所以,现在一切工作和我有很大的自举造型在我的电子邮件中。

相关问题