migration fails on heroku due to activeadmin mailer - ruby-on-rails-3

I am deploying an app to heroku and the app is on rails 3.2 and I have active admin gem installed.
When I run rake db:migrate it fails due to the following error
== DeviseCreateAdminUsers: migrating =========================================
-- create_table(:admin_users)
-> 0.0823s
Sent mail to admin#example.com (3228ms)
rake aborted!
An error has occurred, this and all later migrations canceled:
Connection refused - connect(2)
Wondering what I need to do to fix this. It seems that the Devise gem or ActiveAdmin needs to send mail during the migration process and because it can't if fails.

Try installing the Sendgrid addon:
heroku addons:add sendgrid:starter
If you are deploying to the Aspen or Bamboo stacks, it should work right away. If you are using the Cedar stack, you need to add an additional initializer:
#config/initializers/mail.rb
ActionMailer::Base.smtp_settings = {
:address => 'smtp.sendgrid.net',
:port => '587',
:authentication => :plain,
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp
Taken from: http://devcenter.heroku.com/articles/sendgrid

This is confusing me a little:
Connection refused - connect(2)
Do you have your mail setup? Are you using SendGrid or similar? Remember that Heroku don't provide email services directly.
http://devcenter.heroku.com/articles/smtp

Related

Rails App on AWS Elasticbeanstalk mail send fails with ESMTP No Relay Access Allowed From IP

I have a rails app that I have deployed to AWS Elastic Beanstalk. The app uses devise to handle user authentication, and its set to be able to invite users.
My issue is that when I try to invite a user, I get the following error:
Net::SMTPFatalError (554 secureserver.net ESMTP No Relay Access Allowed From <my_eb_assigned_ip>
(I am hosting the domain on GoDaddy).
In development, the mailer functionality works fine; my smtp settings are set to (common to all environments):
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtpout.secureserver.net",
:port => 80,
:domain => "www.my_domain.com",
:authentication => :plain,
:user_name => "do-not-reply#my_domain.com",
:password => my_pass,
}
And in my production.rb config file:
config.action_mailer.default_url_options = { :host => 'aws_sb.elasticbeanstalk.com' }
Is there another setting I have to enable in Elasticbeanstalk to allow relay access? Or am I missing a production specific setting from my rails configuration?
I figured out it was the port value that I was setting....when I switched the port to 25, it works in production. However, for development, port 25 wasn't working; it would only work in dev when the port was 80.
So I ended up moving the entire smtp mailer settings into the environment specific settings (from the config/environment.rb file), and setting the production port to 25, and the development port to 80, and that appeared to make both environments work.
Edit: After another push, I was seeing the same issue, and none of the ports I tried were resolving the issue. So I ended up switching all my mail functionality to be sent through Amazon SES, and that appears to be functioning great so far.

mandrill send e-mail from localhost

I'm using Mandrill to build a feedback form for users on the website (they fill the form and send me an e-mail).
I want to test the e-mail functionality in development. I use unicorn as a server and my local address is 0.0.0:8080
However I get a 500 server error, Net::SMTPServerBusy : Relay Access Denied
I followed the Heroku instructions step by step.
Here is m application.rb configuration:
config.action_mailer.smtp_settings = {
:address => 'smtp.mandrillapp.com',
:port => '587',
:domain => 'heroku.com',
:user_name => ENV['MANDRILL_USERNAME'],
:password => ENV['MANDRILL_APIKEY']
}
ActionMailer::Base.delivery_method = :smtp
I followed the instructions on mandrill/heroku web page to set up.
I have a .env file set up with a MANDRILL_USERNAME and my MANDRILL_APIKEY
Here is my ActionMailer file:
class FeedbackMailer < ActionMailer::Base
default :from => ""
default :to => "xxx#stanford.edu"
default :subject => "feedback about xxx"
def send_feedback(message)
#debugger
#message = message
mail(:from => message[:sender_email])
end
end
Any help would be appreciated.
I can confirm e-mails get sent in production.
If all of your settings are working in production but not locally, there are a couple of possibilities:
How are you loading the variables from .env to ENV? It's possible the environment variables aren't getting loaded as expected locally. If you hard code the credentials locally, does it work?
You could be running in to an issue with the port or outbound SMTP traffic being blocked. Consider trying port 2525, as it may be less likely to be blocked by local ISPs. Port 465 with SSL enabled may also work even if your ISP is blocking other SMTP traffic

Getting Faraday::Error::ConnectionFailed when connecting from heroku rails app

My company has a simple oauth server at https://auth.vitalvu.com
I'm developing a rails app that needs to make requests to that server (via the omniauth-oauth2 gem). When I try to run the app on Heroku I get the error:
Faraday::Error::ConnectionFailed: SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed
I've tested it as described here.
From the app's rails console on my local machine
connection = Faraday::Connection.new 'https://auth.vitalvu.com'
connection.get '/ping.json'
works just fine.
However, after pushing the app to Heroku, heroku run rails console
connection = Faraday::Connection.new 'https://auth.vitalvu.com'
connection.get '/ping.json'
results in the faraday error and
connection = Faraday::Connection.new 'https://auth.vitalvu.com', :ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}
connection.get '/ping.json'
results in the faraday error and
connection = Faraday::Connection.new 'https://auth.vitalvu.com', :ssl => {:ca_path => "/etc/ssl/certs"}
connection.get '/ping.json'
results in the faraday error
I'm not sure what else to try. Suggestions?
I run heroku restart three times - and than finally is starts to work.

Solr / Sunspot / Rails 3 error: undefined method `closed?' for nil:NilClass

I have this model:
class Book < Item
validates :isbn, :presence => true, :uniqueness => true
has_many :book_chapters
has_many :chapters, :through => :book_chapters
searchable :auto_index => true, :auto_remove => true do
text :title
end
end
And then I have this controller:
class HomeController < ApplicationController
def index
#search = Book.search do
fulltext params[:search]
end
#books = #search.results
[... normal rest of code ...]
end
end
The field "title" is inherited from the more generic Item model. And when the Home controller tries to perform the search, I get this error:
NoMethodError in HomeController#index
undefined method `closed?' for nil:NilClass
There is also this additional warning in the log:
DEPRECATION WARNING: class_inheritable_attribute is deprecated, please use class_attribute method instead. Notice their behavior are slightly different, so refer to class_attribute documentation first. (called from /Users/xxx/Sites/zigzag/app/models/book.rb:7)
Which refers to the line:
searchable :auto_index => true, :auto_remove => true do
in book.rb
Any ideas why I'm getting this error? In other similar posts on stack overflow it seems people forgot to turn on the sunspot server. But I'm running it, and its running fine. I can navigate the Solr Admin just fine. Thanks!
I figured it out. I'm running this app on a Mac OS Lion 10.7.2. The issue was that the rails app was not indeed connected within the sunspot server. But the reason isn't because the sunspot server was missing. It was because rails was using IPv4 addresses while sunspot was expecting IPv6 addresses. The first part of the fix was to change the sunspot.yml config file so that the hostname is 127.0.0.1 and not 'localhost.' Then, in /etc/hosts, comment out the following lines:
#::1 localhost
#fe80::1%lo0 localhost
So that 'localhost' only maps to 127.0.0.1 (which is specified elsewhere in /etc/hosts/). That's it!
One simple answer is that you may have not started your sunspot solr. Try running this rake command:
rake sunspot:solr:start

using apn_sender on heroku

We built an api in rails and are hosting it on heroku and using apn_sender to do the push notifications. We got everything running locally with apn_sender but when we push it to heroku and run
heroku rake apn:sender
we get the following error "Connection refused - Unable to connect to Redis on 127.0.0.1:6379"
We added the redistogo addon.
UPDATE
We added a resque.rb initializer:
require 'resque'
uri = URI.parse(ENV["REDISTOGO_URL"])
Resque.redis = Redis.new(:host => uri.host, :port => uri.port, :password => uri.password)
and called to start up the worker
heroku rake environment apn:sender
and everything seemed to work.
Ok, so after further testing, the update I put in above doesn't work for very long before it crashes. We then followed this http://blog.redistogo.com/2010/07/26/resque-with-redis-to-go/
Changing
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
to
task "apn:setup" => :environment do
ENV['QUEUE'] = '*'
end
and
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
to
desc "Alias for apn:work (To run workers on Heroku)"
task "jobs:work" => "apn:work"
and it worked like a charm. Also note, that we had to add a worker dyno in heroku, which costs .05/hour or $35/month.