所以我对 sidekiq 和 activejob 很陌生,我知道我不需要后台工作一个在创建帐户时发送的邮件,但是我真的很想了解这一切是如何工作的,最好的学习方法就是这样做。 ..
我设置了以下 Job、Mailer 和 Controller 操作,但是当我创建一个新帐户时它失败并出现错误:(为了简洁,我已经发布了整个堆栈)
e_owner: processed outbound mail in 1.3ms
[ActiveJob] [WelcomeEmailJob] [18ba16e9-e3d9-4dd1-b6f4-0a435449c68c] Performed WelcomeEmailJob from Sidekiq(default) in 26.39ms
Completed 404 Not Found in 25051ms (ActiveRecord: 91.9ms)
ActiveRecord::RecordNotFound - Couldn't find Account with 'id'=:
activerecord (5.0.0.1) lib/active_record/core.rb:173:in `find'
app/mailers/welcome_notification_mailer.rb:4:in `welcome_owner'
actionpack (5.0.0.1) lib/abstract_controller/base.rb:188:in `process_action'
actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:97:in `__run_callbacks__'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
activesupport (5.0.0.1) lib/active_support/callbacks.rb:90:in `run_callbacks'
actionpack (5.0.0.1) lib/abstract_controller/callbacks.rb:19:in `process_action'
actionpack (5.0.0.1) lib/abstract_controller/base.rb:126:in `process'
actionmailer (5.0.0.1) lib/action_mailer/rescuable.rb:23:in …Run Code Online (Sandbox Code Playgroud) 使用 devise 和acts_as tennant 构建 Rails 5 应用程序。
不太确定我哪里出错了,我试图在帐户/新下以相同的形式创建帐户和帐户的所有者。
目前我收到以下错误:
/accounts/new 处的 ArgumentError 未找到名称“user”的关联。已经定义了吗?
我已经检查了我的模型和控制器,但似乎无法弄清楚这一点。
账户.rb
class Account < ApplicationRecord
RESTRICTED_NAMES = ["www", "admin", "loadflo"]
has_many :users
before_validation :downcase_name, :create_account_name
strip_attributes only: :account_name, regex: /[^[:alnum:]_-]/
validates :user, presence: true
validates :name, presence: true,
uniqueness: {case_sensitive: false},
exclusion: { in: RESTRICTED_NAMES, message: "This is a restricted name. Please try again or contact support." }
accepts_nested_attributes_for :user
private
def downcase_name
self.name = name.try(:downcase)
end
def create_account_name
self.account_name = self.name
end
end
Run Code Online (Sandbox Code Playgroud)
账户控制器.rb …
我正在使用Apartment Gem构建一个Rails 4应用程序,我仍然坚持如何继续定义我的邮件程序主机..这是一个教程系列的一部分,在几集之后才停止..
现在最大的问题是这一切都在开发模式下工作,但是当我推送到Heroku,创建一个帐户时,会发送确认电子邮件,但是当我去确认时,确认会将我重定向回我的localhost(lvh.me) :3000)并且生产应用程序未获得确认更新.
我的应用程序控制器中有以下内容:
def set_mailer_host
subdomain = current_account ? "#{current_account.subdomain}." : ""
ActionMailer::Base.default_url_options[:host] = "#{subdomain}lvh.me:3000"
end
Run Code Online (Sandbox Code Playgroud)
我想添加一个if else这样的声明:
def set_mailer_host
if environment == development
subdomain = current_account ? "#{current_account.subdomain}." : ""
ActionMailer::Base.default_url_options[:host] = "#{subdomain}lvh.me:3000"
else
subdomain = current_account ? "#{current_account.subdomain}"
ActionMailer::Base.default_url_options[:host] = "#{subdomain}patrolvault.co"
end
Run Code Online (Sandbox Code Playgroud)
我只是想弄明白,或者我是否应该采取另一种方法来解决这个问题?