1

This is frustrating me. For some reason, whenever we are sending an email, ActionMailer insists on checking the User model for a user with that email address.

We have the method defined like this:

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

When we call the method, we are getting the following (note Query Trace is from the 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>, ...

Why is the ActionMailer trying to look up the User in the Users table? We are using LDAP auth via Devise and our gemfile is: 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'

What am I missing here that is causing it to fire that query? I am thinking Devise is trying to be smart here, but I can't figure out where it is injecting itself.

scottr
  • 65
  • 1
  • 6
  • Can you get query_trace to output a full stacktrace somehow? – Shelvacu Apr 06 '16 at 19:40
  • Please add the content of `monitor_mailer/email_importer_errors_found.html.erb` to your question and any email layouts and any partials rendered. (trim the static text if you like, interested in the ERB <% %> stuff) – Lucas Nelson Apr 06 '16 at 23:40
  • After looking at the stacktrace a little deeper (as suggested by shelvacu), it looks like it is an error with the way the Mailkick gem is working. I have entered an issue on github for it (https://github.com/ankane/mailkick/issues/19) and working with the developer to fix it. – scottr Apr 07 '16 at 14:02

0 Answers0