Error de la aplicación Heroku / Rails

Estoy realmente atrapado aquí y estoy preocupado de que mis files de configuration de correo estén completamente desorderados. Mi aplicación parece funcionar bien a nivel local, estoy en Nitrous. Puedo mover bien el master heroku y cuando se abre puedo ver la página de inicio, que es solo un formulario ( https://nameless-taiga-1654.herokuapp.com/ ), sin embargo, una vez que presiono enviar me sale un post de error. Creo que todas mis acciones de correo sobre nitroso están configuradas correctamente, estaba planeando usar sendgrid a través de heroku para ejecutar el lado del correo. Básicamente me perdí y necesito ayuda. Se adjuntan los loggings heroku del error de formulario.

loggings de heroku -t

2015-08-07T11:00:54.501756+00:00 heroku[router]: at=info method=POST path="/contacts" host=nameless-taiga-1654.herokuapp.com request_id=452df9b2-aef8-4a23-9ffb-3ba6781d80 75 fwd="124.149.33.78" dyno=web.1 connect=1ms service=72ms status=500 bytes=1754 2015-08-07T11:00:54.433019+00:00 app[web.1]: Started POST "/contacts" for 124.149.33.78 at 2015-08-07 11:00:54 +0000 2015-08-07T11:00:54.437794+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"Z2Qh/GDIycId0uJk2evhblbKisGXNlIzjtz+xfJoyac=", "contact"=>{"name"=>"John D oe", "phone"=>"040000000", "email"=>"[email protected]", "event_type"=>"Corporate", "comments"=>"Test Comments"}, "commit"=>"Submit"} 2015-08-07T11:00:54.491841+00:00 app[web.1]: 2015-08-07T11:00:54.491846+00:00 app[web.1]: Sent mail to [email protected] (21.8ms) 2015-08-07T11:00:54.491848+00:00 app[web.1]: Completed 500 Internal Server Error in 53ms 2015-08-07T11:00:54.492821+00:00 app[web.1]: 2015-08-07T11:00:54.492824+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)): 2015-08-07T11:00:54.436340+00:00 app[web.1]: Processing by ContactsController#create as HTML 2015-08-07T11:00:54.492826+00:00 app[web.1]: app/mailers/contact_mailer.rb:8:in `contact_email' 2015-08-07T11:00:54.463333+00:00 app[web.1]: Rendenetworking contact_mailer/contact_email.html.erb (0.3ms) 2015-08-07T11:00:54.492828+00:00 app[web.1]: app/controllers/contacts_controller.rb:9:in `create' 2015-08-07T11:00:54.492831+00:00 app[web.1]: 2015-08-07T11:00:54.492830+00:00 app[web.1]: 2015-08-07T11:00:54.492827+00:00 app[web.1]: app/models/contact.rb:7:in `send_email' 

contacts_controller.rb

 class ContactsController < ApplicationController def new @contact = Contact.new end def create @contact = Contact.new(contact_params) if @contact.save flash[:success] = 'Message Sent.' networkingirect_to new_contact_path else flash[:danger] = 'Error occurnetworking, messgage not sent.' networkingirect_to new_contact_path end end end 

models / contact.rb

 class Contact < ActiveRecord::Base validates :name, :email, presence: true after_create :send_email private def send_email ContactMailer.contact_email(self).deliver end end 

mailers / contact_mailer.rb

 class ContactMailer < ActionMailer::Base default to: '[email protected]' def contact_email(contact) @contact = contact mail(from: @contact.email, subject: 'Contact Form Message').deliver end end 

views / contact_mailer / contact_email.html.erb

 <!DOCTYPE html> <html> <head> <title></title> </head> <body> <p>New Message from Hoot and Holla's Contact form, from <%= "#{@contact.name}, #{@contact.email}" %></p> <p><%= @contact.phone %></p> <p><%= @contact.event_type %></p> <p><%= @contact.comments %></p> </body> </html> 

application.html.erb

 <!DOCTYPE html> <html> <head> <title>HootandhollaLp</title> <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> <%= csrf_meta_tags %> </head> <body> <div class="container"> <% flash.each do |key, value| %> <div class="alert alert-<%= key %> alert-dismissible"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button> <%= value %> </div> <% end %> <%= yield %> </div> </body> </html> 

@Pavan @alexsmn Espero que esto ayude?


config / environments / production.rb

 Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # Code is not reloaded between requests. config.cache_classes = true # Eager load code on boot. This eager loads most of Rails and # your application in memory, allowing both threaded web servers # and those relying on copy on write to perform better. # Rake tasks automatically ignore this option for performance. config.eager_load = true # Full error reports are disabled and caching is turned on. config.consider_all_requests_local = false config.action_controller.perform_caching = true # Enable Rack::Cache to put a simple HTTP cache in front of your application # Add `rack-cache` to your Gemfile before enabling this. # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. # config.action_dispatch.rack_cache = true # Disable Rails's static asset server (Apache or nginx will already do this). config.serve_static_assets = false # Compress JavaScripts and CSS. config.assets.js_compressor = :uglifier # config.assets.css_compressor = :sass # Do not fallback to assets pipeline if a precompiled asset is missed. config.assets.compile = false # Generate digests for assets URLs. config.assets.digest = true # Version of your assets, change this if you want to expire all your assets. config.assets.version = '1.0' # Specifies the header that your server uses for sending files. # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. # config.force_ssl = true # Set to :debug to see everything in the log. config.log_level = :info # Prepend all log lines with the following tags. # config.log_tags = [ :subdomain, :uuid ] # Use a different logger for distributed setups. # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) # Use a different cache store in production. # config.cache_store = :mem_cache_store # Enable serving of images, stylesheets, and JavaScripts from an asset server. # config.action_controller.asset_host = "http://assets.example.com" # Precompile additional assets. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # config.assets.precompile += %w( search.js ) # Ignore bad email addresses and do not raise email delivery errors. # Set this to true and configure the email server for immediate delivery to raise delivery errors. # config.action_mailer.raise_delivery_errors = false # Enable locale fallbacks for I18n (makes lookups for any locale fall back to # the I18n.default_locale when a translation cannot be found). config.i18n.fallbacks = true # Send deprecation notices to registenetworking listeners. config.active_support.deprecation = :notify # Disable automatic flushing of the log to improve performance. # config.autoflush_log = false # Use default logging formatter so that PID and timestamp are not suppressed. config.log_formatter = ::Logger::Formatter.new # Do not dump schema after migrations. config.active_record.dump_schema_after_migration = false end 

config / environment.rb

 # Load the Rails application. require File.expand_path('../application', __FILE__) # Initialize the Rails application. Rails.application.initialize! ActionMailer::Base.smtp_settings = { :address => 'smtp.sendgrid.net', :port => '587', :authentication => :plain, :user_name => ENV['SENDGRID_USERNAME'], :password => ENV['SENDGRID_PASSWORD'], :domain => 'heroku.com', :enable_startstls_auto => true } 

He tenido el mismo problema al trabajar con mi proyecto actual. En realidad, como descubrí, este es un problema de authentication de Gmail. Su aplicación está intentando iniciar session en la count de Gmail y no puede hacerlo porque Gmail no ve ni reconoce el correo electrónico y la contraseña encryptions. Resolví temporalmente este problema escribiendo los valores necesarios en mis smtp_settings directamente, como:

  smtp_settings = { ... :user_name => "...your gmail email...", :password => "...your gmail password...", ... } 

Además, cambié la configuration de security de la count de Gmail: desactivé la authentication doble y permití que otras aplicaciones less seguras accedieran a mi count. Por lo tanto, actualmente la aplicación se implementa en Heroku y funciona. Sin embargo, desde el punto de vista de la security cibernética, mi solución es bastante peligrosa, por lo que aún estoy buscando otras mejores.

EDITADO !!! Hay una mejor manera de encriptar la configuration de la count de Gmail. En mi file .bashrc (está oculto en el directory raíz de la computadora – presione Ctrl + H para revelarlo) escribí las siguientes líneas de código:

  export GMAIL_NAME=necessary value here export GMAIL_PASSWORD=necessary value here 

Después de esto, también cambié mis smtp_settings una vez más, como:

  smtp_settings = { ... user_name: ENV['GMAIL_NAME'], password: ENV['GMAIL_PASSWORD'], ... } 

Finalmente, configuré la configuration de repo en Heroku: Heroku / Aplicaciones personales / myApp / Configuración, sección "Variables de configuration" al agregar dos nuevas variables GMAIL_NAME y GMAIL_PASSWORD con los valores necesarios.

Funcionó.

Intente configurar lo siguiente en su file production.rb :

 config.action_mailer.delivery_method = :smtp config.action_mailer.perform_deliveries = true config.action_mailer.default_url_options = { host: 'nameless-taiga-1654.herokuapp.com' } 

Además, para verificar que la configuration sea correcta, puede ejecutar la heroku config .