heroku Errno::ENOENT (No such file or directory - /assets/)

I have a problem that occurs only in a production environment, deployed at heroku.

The Heroku logs says:

Parameters: {"utf8"=>"✓",
             "users"=>{"name"=>"name", "email"=>"example@example.com", 
             "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

This error happened after adding a Mailer component with these characteristics:

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

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



with the following templete new_user_creation.html.erb :

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

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

       <p class="indented"><%=t("confirm_account_creation")%><p>
       <p class="indented"><a href="<%=@url%>">COMPLETE ACCOUNT CREATION PROCESS</a></p>





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

My 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'

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

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

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

The interesting part of 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"]



Are you using the premailer-rails3 gem? I found that version 1.2.0 caused this exact same problem. Downgrading to 1.1.0 fixed it. Hope that helps!

This is not a heroku-only issue. This exception is thrown when email.css does not exist or (as of premailer-rails 1.3.x) a inline style tag does not exist.

The solution is to add email.css to your assets folder or add an empty <style type="text/css"> </style> to your email HTML.

Been struggling with this for a number of hours and thought I would add my solution for your benefit.

Using premailer-rails3 (1.3.1)

I wanted my email CSS to match the bootstrap styling, so I thought a lazy way would be to simply use <%= stylesheet_link_tag "application", :media => "all" %> however this causes the cannot find /assets/ issue.

So I ended up doing the following:

  1. Needed to remove *= require_tree from my application.css, which is good practice anyway, and required by main css file
*= require_self
*= require <MyMainSiteCSS>
  1. Created app/stylesheets/email.css with the following
@import "bootstrap";
@import "bootstrap-responsive";
  1. Changed the head of my email view to be:
  <link href="email.css" media="all" rel="stylesheet" type="text/css">

So, now everything is working and I have great bootstrap styling in my emails.

Need Your Help

Vertical centered div with jQuery

jquery html center vertical-alignment centering

I am trying to center my div vertically in another div with 100% dimensions. My code is working but it gives some weird bug.

How to make block local variables the default in ruby 1.9?

ruby scope closures

Ruby 1.9 gives the ability to define variables that are just local to a block and do not close over variables of the same name in an outer scope: