这让我很沮丧。出于某种原因,每当我们发送电子邮件时,ActionMailer 都会坚持检查具有该电子邮件地址的用户的用户模型。
我们有这样定义的方法:
class MonitorMailer < ActionMailer::Base
default :from => "validemail@ourplace.org"
def email_importer_errors_found
mail(to: "validto@ourplace.org", subject: "Errors found in import error folder ")
end
end
当我们调用该方法时,我们得到以下信息(注意 Query Trace 来自 Active Record Query Trace gem(https://github.com/ruckus/active-record-query-trace):
Rendered monitor_mailer/email_importer_errors_found.html.erb (0.2ms)
User Load (2.4ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'validto@ourplace.org' ORDER BY `users`.`id` ASC LIMIT 1
Query Trace > app/mailers/monitor_mailer.rb:28:in `email_importer_errors_found'
Mysql2::Error: Unknown column 'users.email' in 'where clause': SELECT `users`.* FROM `users` WHERE `users`.`email` = 'validto@ourplace.org' ORDER BY `users`.`id` ASC LIMIT 1
MonitorMailer#email_importer_errors_found: processed outbound mail in 167.3ms
=> #<Mail::Message:108716380, Multipart: false, Headers: <Date: Wed, 06 Apr 2016 13:56:55 -0400>, ...
为什么 ActionMailer 试图在用户表中查找用户?我们通过 Devise 使用 LDAP 身份验证,我们的 gemfile 是: source ' http://rubygems.org '
gem 'rails', '4.1.15'
gem "mysql2", '0.3.15'
gem 'protected_attributes', '~> 1.0.8'
gem 'devise', '~> 3.4.1'
gem 'net-ldap', '~> 0.3.1'
gem 'devise_ldap_authenticatable', '0.8.4'
gem 'ruby-oci8', '~> 2.2.1'
gem 'nokogiri', '~> 1.6', '>= 1.6.7.1'
gem "net-sftp"
gem 'sshkit', '1.8.1'
gem 'prawn'
gem "prawnto_2", :require => "prawnto"
gem 'prawn-labels'
gem 'prawn-table'
gem 'whenever', "0.9.4", :require => false
gem 'delayed_job', '4.0.1'
gem 'delayed_job_active_record', '4.0.1'
gem 'mailboxer', "~> 0.13.0"
gem 'mailkick', '~> 0.1.3'
gem "daemons", '~> 1.1.9'
gem 'hairtrigger', '0.2.17'
group :development do
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rvm', '~> 0.1.2'
gem 'capistrano-rails', '~> 1.1'
gem 'capistrano3-delayed-job', '~> 1.0'
gem 'brakeman'
gem 'quiet_assets'
gem 'rack-insight'
gem 'active_record_query_trace'
end
group :development, :test do
gem 'rspec-rails', '2.14.0'
end
gem 'paper_trail', '~> 3.0.2'
gem 'settingslogic'
gem 'cancancan', '1.12.0'
gem 'attr_encrypted', '1.3.5'
gem 'jquery-rails', '~> 3.1.0'
gem 'jquery-ui-rails'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
我在这里缺少什么导致它触发该查询?我在想 Devise 在这里试图变得聪明,但我无法弄清楚它在哪里注入自己。