"✓", "authenticity_t-6ren">
gpt4 book ai didi

ruby-on-rails - heroku Errno::ENOENT(没有这样的文件或目录 -/assets/)

转载 作者:行者123 更新时间:2023-12-03 00:08:33 25 4
gpt4 key购买 nike

我遇到的问题出现在部署在heroku 的生产环境中。

Heroku 日志说:

[...]
Parameters: {"utf8"=>"✓",
"authenticity_token"=>"...",
"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

添加具有以下特征的 Mailer 组件后发生此错误:

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

使用以下模板 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="<%=@url%>">COMPLETE ACCOUNT CREATION PROCESS</a></p>
</td>
</tr>


</table>

</body>

</html>

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

最佳答案

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

解决办法是添加email.css到您的 Assets 文件夹或添加一个空的 <style type="text/css"> </style>到您的电子邮件 HTML。

关于ruby-on-rails - heroku Errno::ENOENT(没有这样的文件或目录 -/assets/),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11035799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com