pboling/sanitize_email

Uninitialize constant SanitizeEmail

dimameshcharakou opened this issue · 4 comments

Hey,

I have smtp.rb in config/initializers. In this file I have standard config SanitizeEmail gem.
When I tried to use sanitize_email gem on production I got error: Uninitialize constant SanitizeEmail in the unicorn.log.

VPS:
ruby 1.9.3
rails 3.2.13
unicorn
nginx
sanitize_email 1.0.6

I think perhaps there is an issue with the file being named smtp.rb, though that's a blind hunch. My initializer file is called sanitize_email.rb and contains:

SanitizeEmail::Config.configure do |config|
  config[:sanitized_to] =         'team@example.com'
  # sanitize emails from staging and test, or set whatever logic should turn sanitize_email on and off here:
  # We use mailcatcher in development
  config[:activation_proc] =   Proc.new { %w(test staging).include?(Rails.env) }
  config[:use_actual_email_prepended_to_subject] = true   # or false
  config[:use_actual_environment_prepended_to_subject] = true   # or false
  config[:use_actual_email_as_sanitized_user_name] = false # or true
end

Thanks for quick reply.

After I created separate file sanitize_email.rb in the config/initializers/ I got error:
NameError: uninitialized constant SanitizeEmail

At the first I used rails 3.0.17 and sanitize_email 0.3.7 all works fine, but after update rails to 3.2.13 and sanitize_email to 1.0.6 I start to get error.

I confused because in the production in rails console I can use SanitizeEmail constant and don't get error.

When I restarted unicorn app didn't work, but when I stop and then start unicorn all works.

You will need to run unicorn within the bundler environment for it to work, as that's the only way that the gems are loaded in the same way they are in production.

What is the command you use to start/stop/restart unicorn? Starting it should have bundle exec in front of it. The only server I know of that includes the bundler environment is foreman. All others must use bundle exec.

It may work in some limited use cases without bundle exec but you will find something that will not work without bundle exec eventually, in addition to not running in a production similar manner.