Send email via Ruby code on Heroku - ruby

I'm having problems sending email via my Ruby code. You can see my full code on GitHub.
UPDATE: the below code has been amended to reflect suggestions from #Gaurish
UPDATE2: looks like gmail refused the login attempt - I received an email from them to warn me some unknown application tried to access my account but they disabled it
The specific class is here:
require 'net/smtp'
=begin
http://apidock.com/ruby/v1_9_3_125/Net/SMTP/start/class
https://devcenter.heroku.com/articles/config-vars
I added the following config vars to Heroku
heroku config:add GM_USR=xxxx
heroku config:add GM_PSW=xxxx
=end
class Email
def initialize (to, from, subject, body)
#to = to
#from = from
#subject = subject
#body = body
#message = <<MESSAGE_CONTENT
From: User <#{#from}>
To: Integralist <#{#to}>
MIME-Version: 1.0
Content-type: text/html
Subject: #{#subject}
#{#body}
MESSAGE_CONTENT
#smtp = Net::SMTP.new('smtp.gmail.com', 587)
end
def send_email
#smtp.enable_starttls
#smtp.start('furious-wind-9309.herokuapp.com', ENV['GM_USR'], ENV['GM_PSW'], :login) do |smtp|
#smtp.send_message(#message, #from, #to)
end
end
end
I'm calling it like so:
email = Email.new('myemail#gmail.com', params[:email], 'test subject', params[:message]);
email.send_mail
But when I execute the code I get the error displayed on screen: 535-5.7.1 Please log in with your web browser and then try again. Learn more at
I checked the logs and I get...
2012-06-13T08:01:08+00:00 heroku[router]: POST furious-wind-9309.herokuapp.com/contact dyno=web.1 queue=0 wait=0ms service=628ms status=500 bytes=2060
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in `context'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `block in call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1416:in `synchronize'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.2/lib/sinatra/base.rb:1334:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:80:in `block in pre_process'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `catch'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/thin-1.3.1/lib/thin/connection.rb:78:in `pre_process'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `call'
2012-06-13T08:01:08+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `block in spawn_threadpool'
2012-06-13T08:01:08+00:00 app[web.1]: 82.69.39.185 - - [13/Jun/2012 08:01:08] "POST /contact HTTP/1.1" 500 2060 0.6254
I know people will likely suggest ActionMailer or Pony, but I'd rather not use those or have those suggested to me please. I'd instead like a solution that helps fix the above code instead.

[Update 1]
If gmail doesn't work for you, you can use SendGrid Addon which gives you upto 200emails per day at no charge.
Here is a sample(taken from docs) on how to use their STMP API with mail gem
require 'mail'
Mail.defaults do
delivery_method :smtp, { :address => "smtp.sendgrid.net",
:port => 587,
:domain => "yourdomain.com",
:user_name => "yourusername#domain.com",
:password => "yourPassword",
:authentication => 'plain',
:enable_starttls_auto => true }
end
mail = Mail.deliver do
to 'yourRecipient#domain.com'
from 'Your Name <name#domain.com>'
subject 'This is the subject of your email'
text_part do
body 'Hello world in text'
end
html_part do
content_type 'text/html; charset=UTF-8'
body '<b>Hello world in HTML</b>'
end
end
Using Sendgrid is much better solution because you also get access Advanced reporting & analyticss which are not available with gmail. Also, there is no restriction on "from" addresses in sendgrid.
With Heroko, you can't send emails directly from localhost because Heroku does not provide an outgoing mail service.
so you will have to consider an external smtp server for sending your emails. popular ones are Gmail & Sendgrid
this is just one trade-off of using a cloud computing platform like heroku.
With Gmail, try doing something like this:
require 'net/smtp'
msg = "your message goes here"
smtp = Net::SMTP.new 'smtp.gmail.com', 587
smtp.enable_starttls
smtp.start(YourDomain, YourAccountName, YourPassword, :login) do
smtp.send_message(msg, FromAddress, ToAddress)
end

If you try:
#email = Email.new('mark.mcdx#gmail.com', params[:email], 'test subject', params[:message])
#email.send_email

Just load up SendGrid as an add-on and it works right out of the box. Plus you get a whole suite of analytics for troubleshooting bounces, deliveries, etc...

Related

Ruby net/http can't connect to a TLS proxy

Rubys net/http allows you to specify a proxy to route all requests through like this:
Net::HTTP.new("host", "443", "proxyHost", 8080, "proxyUsername", "password")
This works fine when used with HTTP proxy however fails when a TLS proxy used instead of HTTP:
def tls_proxy(data)
uri = URI("https://example.com/post")
client = Net::HTTP.new("host", "443", "proxyHost", 8443, "proxyUsername", "password")
client.ssl_version = :TLSv1_2
client.use_ssl = true
request = Net::HTTP::Post.new(uri.path)
request['Content-type'] = 'application/json'
request.body = data
client.request(request)
end
Uncaught exception: end of file reached
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/protocol.rb:225:in `rbuf_fill'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/protocol.rb:191:in `readuntil'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/protocol.rb:201:in `readline'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:40:in `read_status_line'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http/response.rb:29:in `read_new'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:969:in `connect'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:930:in `do_start'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:919:in `start'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/net/http.rb:1470:in `request'
/Users/laptop/Projects/tls-proxy-ruby/example-https.rb:47:in `tls_proxy'
/Users/laptop/Projects/tls-proxy-ruby/example-https.rb:60:in `<top (required)>'
Is there a way to make it work with TLS proxy or perhaps there is an alternative to this library that supports TLS proxy?
You could try httparty gem instead.
require 'httparty'
options = {
http_proxyaddr: '127.0.0.1',
http_proxyport: '8443',
http_proxyuser: 'johndoe',
http_proxypass: '123456'
}
response = HTTParty.get('https://example.com', options)

SSL_connect returned=1 errno=0 state=unknown state: unknown protocol

After reading through many posts I couldn't find a solution to my problem. I've made a test connection with www.smtper.net which was successful. My error.log only tells me the error:
OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=unknown state: unknown protocol
app/controllers/passwords_controller.rb:11:in `create'
Maybe it has something to do with my nginx settings?
Issue
I'm trying to configure my smtp via mailgun (or gmail) but without success.
My configuration in developement.rb looks like:
config.action_mailer.default_url_options = { :host => "xxxxx:8765" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mail.google.com",
:user_name => "xxx#gmail.com",
:password => "xxxxxx",
:authentication => :plain,
:enable_starttls_auto => true
}
And the error is thrown at the action create, line 11:
AccountMailer.password_reset_email(#account).deliver
I have installed OpenSSL 1.0.1f on my development server
TRACE
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in `connect_nonblock'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/protocol.rb:44:in `ssl_socket_connect'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:584:in `tlsconnect'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:552:in `do_start'
/root/.rbenv/versions/2.5.1/lib/ruby/2.5.0/net/smtp.rb:518:in `start'
mail (2.7.0) lib/mail/network/delivery_methods/smtp.rb:109:in `start_smtp_session'
mail (2.7.0) lib/mail/network/delivery_methods/smtp.rb:100:in `deliver!'
mail (2.7.0) lib/mail/message.rb:2160:in `do_delivery'
mail (2.7.0) lib/mail/message.rb:260:in `block in deliver'
actionmailer (4.2.8) lib/action_mailer/base.rb:543:in `block in deliver_mail'
activesupport (4.2.8) lib/active_support/notifications.rb:164:in `block in instrument'
activesupport (4.2.8) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
activesupport (4.2.8) lib/active_support/notifications.rb:164:in `instrument'
actionmailer (4.2.8) lib/action_mailer/base.rb:541:in `deliver_mail'
mail (2.7.0) lib/mail/message.rb:260:in `deliver'
actionmailer (4.2.8) lib/action_mailer/message_delivery.rb:85:in `deliver_now'
actionmailer (4.2.8) lib/action_mailer/message_delivery.rb:105:in `deliver'
app/controllers/passwords_controller.rb:11:in `create'
What happens if you try this settings and get rid of everything else you currently have:
# /config/environments/development.rb
# Gmail configuration
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'example.com',
user_name: ENV['EMAIL_USER'],
password: ENV['EMAIL_PASS'],
authentication: 'plain',
enable_starttls_auto: true
}
I'm not sure you need to monkey with smtper.net but perhaps see this, even though it's very old, it probably should still work:
http://blog.napcs.com/2013/07/21/rails_ssl_simple_wa/
You'll need to set those environment variables as you obviously should never want to commit credentials in your git repo.
But also see these posts as you may need to do some other things for gmail
(Ruby) Getting Net::SMTP working with Gmail...?
Rails 4, how to correctly configure smtp settings (gmail)

Unable to log into Rails 5 app in Heroku with the Devise gem

In a moment of insanity, I decided to make a Rails 5 app that uses the Devise gem and Omniauth. Everything appears to work in the development environment (though I haven't configured it to send emails from there...the cukes are passing! =D) but when I push it to Heroku and migrate (and even when I try restarting the dyno), I can't log in using a valid email and password (or via omniauth but that was expected), when I try to sign up, the account is created but no authentication email is ever sent. I can't resend the confirmation email and when I tried confirming an existing account via rails console in Heroku, I was then unable to reset the account's password using the forgotten password link on the app. No matter what I do, I receive the generic 500 error advising me to check my logs. As far as I can tell, the problem seems to be with Devise or ActionMailer as the rest of the site loads correctly.
I've tried changing my Gmail settings on the following pages:
Display Unlock Captcha
Less Secure Apps (which I haven't had to use for my Rails 4 apps recently)
I've tried making various tweaks to the config files and such but so far nothing's worked.
Heroku's logs (from when I tried to send a forgotten password email from the site)
2016-08-27T08:22:49.275213+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:232:in `block in conditional'
2016-08-27T08:22:49.275273+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `block in call'
2016-08-27T08:22:49.275332+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `call'
2016-08-27T08:22:49.275302+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `each'
2016-08-27T08:22:49.275656+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:334:in `rollback_active_record_state!'
2016-08-27T08:22:49.275713+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/suppressor.rb:41:in `save'
2016-08-27T08:22:49.275774+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/bundler/gems/devise-4c3838bb759e/lib/devise/models/recoverable.rb:45:in `send_reset_password_instructions'
2016-08-27T08:22:49.275362+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
2016-08-27T08:22:49.275509+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:202:in `within_new_transaction'
2016-08-27T08:22:49.275391+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_commit_callbacks'
2016-08-27T08:22:49.275155+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:382:in `block in make_lambda'
2016-08-27T08:22:49.275420+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:354:in `committed!'
2016-08-27T08:22:49.275451+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:87:in `commit_records'
2016-08-27T08:22:49.275684+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:318:in `save'
2016-08-27T08:22:49.276127+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:101:in `__run_callbacks__'
2016-08-27T08:22:49.276268+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
2016-08-27T08:22:49.275479+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/transaction.rb:178:in `commit_transaction'
2016-08-27T08:22:49.276857+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal.rb:262:in `dispatch'
2016-08-27T08:22:49.276997+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:46:in `serve'
2016-08-27T08:22:49.275241+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:456:in `call'
2016-08-27T08:22:49.277110+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:725:in `call'
2016-08-27T08:22:49.277194+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:186:in `call!'
2016-08-27T08:22:49.277251+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:186:in `call!'
2016-08-27T08:22:49.277279+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:164:in `call'
2016-08-27T08:22:49.277307+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/warden-1.2.6/lib/warden/manager.rb:35:in `block in call'
2016-08-27T08:22:49.277447+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/head.rb:12:in `call'
2016-08-27T08:22:49.277630+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_call_callbacks'
2016-08-27T08:22:49.277658+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
2016-08-27T08:22:49.277856+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/tagged_logging.rb:70:in `block in tagged'
2016-08-27T08:22:49.278095+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/executor.rb:12:in `call'
2016-08-27T08:22:49.275538+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/abstract/database_statements.rb:232:in `transaction'
2016-08-27T08:22:49.275567+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:211:in `transaction'
2016-08-27T08:22:49.275597+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:392:in `with_transaction_returning_status'
2016-08-27T08:22:49.275859+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
2016-08-27T08:22:49.275927+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/rendering.rb:30:in `process_action'
2016-08-27T08:22:49.276069+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
2016-08-27T08:22:49.276211+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/abstract_controller/callbacks.rb:19:in `process_action'
2016-08-27T08:22:49.276296+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:164:in `block in instrument'
2016-08-27T08:22:49.276800+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionview-5.0.0.1/lib/action_view/rendering.rb:30:in `process'
2016-08-27T08:22:49.277223+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:164:in `call'
2016-08-27T08:22:49.277587+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:97:in `__run_callbacks__'
2016-08-27T08:22:49.277799+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/rack/logger.rb:36:in `call_app'
2016-08-27T08:22:49.278008+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/method_override.rb:22:in `call'
2016-08-27T08:22:49.278133+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/static.rb:136:in `call'
2016-08-27T08:22:49.275626+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/transactions.rb:319:in `block in save'
2016-08-27T08:22:49.275743+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/bundler/gems/devise-4c3838bb759e/lib/devise/models/recoverable.rb:88:in `set_reset_password_token'
2016-08-27T08:22:49.275802+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/bundler/gems/devise-4c3838bb759e/lib/devise/models/recoverable.rb:119:in `send_reset_password_instructions'
2016-08-27T08:22:49.275901+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/abstract_controller/base.rb:188:in `process_action'
2016-08-27T08:22:49.275956+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
2016-08-27T08:22:49.275984+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:126:in `call'
2016-08-27T08:22:49.276012+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:126:in `call'
2016-08-27T08:22:49.276041+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:506:in `block (2 levels) in compile'
2016-08-27T08:22:49.276466+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activerecord-5.0.0.1/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
2016-08-27T08:22:49.277082+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/journey/router.rb:26:in `serve'
2016-08-27T08:22:49.277532+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/cookies.rb:613:in `call'
2016-08-27T08:22:49.277714+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
2016-08-27T08:22:49.278038+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/runtime.rb:22:in `call'
2016-08-27T08:22:49.276098+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:455:in `call'
2016-08-27T08:22:49.276381+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
2016-08-27T08:22:49.276885+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
2016-08-27T08:22:49.277504+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/session/abstract/id.rb:216:in `call'
2016-08-27T08:22:49.278267+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/puma-3.6.0/lib/puma/server.rb:415:in `process_client'
2016-08-27T08:22:49.276155+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:750:in `_run_process_action_callbacks'
2016-08-27T08:22:49.276239+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/rescue.rb:20:in `process_action'
2016-08-27T08:22:49.276437+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/searchkick-1.3.3/lib/searchkick/logging.rb:153:in `process_action'
2016-08-27T08:22:49.277025+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/journey/router.rb:39:in `block in serve'
2016-08-27T08:22:49.277391+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/etag.rb:25:in `call'
2016-08-27T08:22:49.277884+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/tagged_logging.rb:26:in `tagged'
2016-08-27T08:22:49.278352+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/puma-3.6.0/lib/puma/thread_pool.rb:116:in `block in spawn_thread'
2016-08-27T08:22:49.276324+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
2016-08-27T08:22:49.276352+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/notifications.rb:164:in `instrument'
2016-08-27T08:22:49.276913+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/route_set.rb:32:in `serve'
2016-08-27T08:22:49.276969+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:46:in `call'
2016-08-27T08:22:49.277743+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/debug_exceptions.rb:49:in `call'
2016-08-27T08:22:49.277828+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/rack/logger.rb:24:in `block in call'
2016-08-27T08:22:49.277914+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/tagged_logging.rb:70:in `tagged'
2016-08-27T08:22:49.277980+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/request_id.rb:24:in `call'
2016-08-27T08:22:49.278239+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/puma-3.6.0/lib/puma/server.rb:578:in `handle_request'
2016-08-27T08:22:49.276409+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/params_wrapper.rb:248:in `process_action'
2016-08-27T08:22:49.277560+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/callbacks.rb:38:in `block in call'
2016-08-27T08:22:49.277686+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/callbacks.rb:36:in `call'
2016-08-27T08:22:49.277167+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:164:in `call'
2016-08-27T08:22:49.277336+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/warden-1.2.6/lib/warden/manager.rb:34:in `catch'
2016-08-27T08:22:49.277953+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/rack/logger.rb:24:in `call'
2016-08-27T08:22:49.275829+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/bundler/gems/devise-4c3838bb759e/app/controllers/devise/passwords_controller.rb:13:in `create'
2016-08-27T08:22:49.276184+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/callbacks.rb:90:in `run_callbacks'
2016-08-27T08:22:49.277054+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/journey/router.rb:26:in `each'
2016-08-27T08:22:49.277139+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/omniauth-1.3.1/lib/omniauth/strategy.rb:186:in `call!'
2016-08-27T08:22:49.277419+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/conditional_get.rb:38:in `call'
2016-08-27T08:22:49.276773+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/abstract_controller/base.rb:126:in `process'
2016-08-27T08:22:49.276828+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_controller/metal.rb:190:in `dispatch'
2016-08-27T08:22:49.276941+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/routing/mapper.rb:16:in `block in <class:Constraints>'
2016-08-27T08:22:49.277364+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/warden-1.2.6/lib/warden/manager.rb:34:in `call'
2016-08-27T08:22:49.277475+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/session/abstract/id.rb:222:in `context'
2016-08-27T08:22:49.277771+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
2016-08-27T08:22:49.278067+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/activesupport-5.0.0.1/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
2016-08-27T08:22:49.278154+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/rack-2.0.1/lib/rack/sendfile.rb:111:in `call'
2016-08-27T08:22:49.278184+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/railties-5.0.0.1/lib/rails/engine.rb:522:in `call'
2016-08-27T08:22:49.278211+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/puma-3.6.0/lib/puma/configuration.rb:225:in `call'
2016-08-27T08:22:49.278324+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/puma-3.6.0/lib/puma/thread_pool.rb:116:in `call'
2016-08-27T08:22:49.278296+00:00 app[web.1]: [0635e4c5-2a5f-467e-b067-a9906868f73d] vendor/bundle/ruby/2.2.0/gems/puma-3.6.0/lib/puma/server.rb:275:in `block in run'
My current Gemfile
source 'https://rubygems.org'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.0'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
gem 'jquery-rails'
gem 'sprockets', '>=3.0.0.beta'
#gem 'sprockets-es6'
gem 'haml'
gem 'nokogiri'
gem 'devise', git: 'https://github.com/plataformatec/devise.git', branch: 'master'
gem 'omniauth'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'omniauth-instagram'
gem 'cancancan'
gem 'figaro'
gem 'humanize_boolean'
gem 'carrierwave', git: 'https://github.com/carrierwaveuploader/carrierwave'
gem 'mini_magick', '~> 3.8.0'
gem 'fog'
gem 'geocoder'
gem 'elasticsearch-model', git: 'https://github.com/elasticsearch/elasticsearch-rails.git'
gem 'elasticsearch-rails', git: 'https://github.com/elasticsearch/elasticsearch-rails.git'
gem 'searchkick'
gem 'cocoon'
gem 'owlcarousel-rails'
# Use Capistrano for deployment
gem 'capistrano-rails', group: :development
group :test do
gem 'selenium-webdriver'
end
group :development, :test do
gem 'pry-byebug', platform: :mri
gem 'rspec-rails'
gem 'simplecov'
gem 'factory_girl_rails'
gem 'launchy'
gem 'cucumber-rails', :require => false
gem 'database_cleaner'
gem 'faker'
gem 'rails-controller-testing'
gem 'capybara'
gem 'jasmine'
end
group :development do
gem 'web-console'
gem 'listen', '~> 3.0.5'
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :production do
gem 'rails_12factor'
gem 'aws-sdk'
end
config/environments/production.rb
Rails.application.configure do
config.cache_classes = true
config.eager_load = true
config.consider_all_requests_local = false
config.action_controller.perform_caching = true
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
config.assets.js_compressor = :uglifier
config.assets.compile = true
config.log_level = :debug
config.log_tags = [ :request_id ]
config.action_mailer.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_url_options = {
host: ENV["MAILER_HOST"], #Rails.application.secrets.mailer_host,
from: ENV["MAILER_FROM"]#Rails.application.secrets.mailer_from
}
Rails.application.routes.default_url_options[:host] = ENV["MAILER_HOST"]#Rails.application.secrets.mailer_host
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: ENV["GMAIL_DOMAIN"],#Rails.application.secrets.gmail_domain,
authentication: :plain,
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],#Rails.application.secrets.gmail_username,
password: ENV["GMAIL_PASSWORD"]#Rails.application.secrets.gmail_password
}
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.log_formatter = ActiveSupport::Logger::Formatter.new
# require 'syslog/logger'
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name')
if ENV["RAILS_LOG_TO_STDOUT"].present?
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end
config.active_record.dump_schema_after_migration = false
Elasticsearch::Model.client = Elasticsearch::Client.new host: ENV['SEARCHBOX_SSL_URL']
end
As you can see, I originally tried accessing the environment variables from the secrets file (which contained the environment variable names and referred back to Heroku's config settings but have since tried adding the variables directly to the configuration files themselves. Pushing these new changes to Heroku hasn't made much of a difference however.
config/initializers/devise.rb
Devise.setup do |config|
config.mailer_sender = ENV["MAILER_FROM"]
config.mailer = 'Devise::Mailer'
config.parent_mailer = 'ActionMailer::Base'
require 'devise/orm/active_record'
config.authentication_keys = [:email]
config.strip_whitespace_keys = [:email]
config.http_authenticatable = false
config.skip_session_storage = [:http_auth]
config.stretches = Rails.env.test? ? 1 : 11
config.confirmation_keys = [:email]
config.password_length = 6..128
config.email_regexp = /\A[^#\s]+#[^#\s]+\z/
config.reset_password_within = 6.hours
config.sign_out_via = :delete
config.omniauth :twitter, ENV["TWITTER_APP_ID"], ENV["TWITTER_APP_SECRET"]# Rails.application.secrets.twitter_app_id, Rails.application.secrets.twitter_app_secret
config.omniauth :facebook, ENV["FACEBOOK_APP_ID"], ENV["FACEBOOK_APP_SECRET"]# Rails.application.secrets.facebook_app_id, Rails.application.secrets.facebook_app_secret
config.omniauth :instagram, ENV["INSTAGRAM_APP_ID"], ENV["INSTAGRAM_APP_SECRET"]# Rails.application.secrets.instagram_app_id, Rails.application.secrets.instagram_app_secret
end
Devise routes
devise_scope :squatter do
devise_for :squatters, controllers: {
sessions: "squatters/sessions",
registrations: "squatters/registrations",
passwords: "squatters/passwords",
confirmations: "squatters/confirmations",
omniauth_callbacks: "squatters/omniauth_callbacks"
}
end
resources :squatters, only: [:index, :show] do
member do
get :submissions_pending_approval
end
resources :messages, except: [:destroy, :edit, :index]
end
Devise settings for the model I'm using
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :omniauthable, omniauth_providers: [:facebook, :twitter, :instagram]
Most of my devise controllers call super on the controller they inherit from. The only one I've changed is the Omniauth one. I was mostly just following a tutorial for multiple omniauth identities (sourcey.com/rails-4-omniauth-using-devise-with-twitter-facebook-and-linkedin) so this might be a red herring.
class Squatters::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def self.provides_callback_for(provider)
class_eval %Q{
def #{provider}
#squatter = Squatter.find_for_oauth(env["omniauth.auth"], current_squatter)
if #squatter.persisted?
sign_in_and_redirect #squatter, event: :authentication
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_squatter_registration_url
end
end
}
end
[:twitter, :facebook, :instagram].each do |provider|
provides_callback_for provider
end
def after_sign_in_path_for(resource)
if resource.email_verified?
super resource
else
finish_signup_path(resource)
end
end
end
As mentioned earlier, I've tried running heroku run rake db:migrate --app my_apps_name and tried running heroku restart --app my_apps_name. Does anyone know if there's something that I might have missed or if this would simply indicate the presence of a bug in the latest version of Devise?
Hi did you check your config/environments folder? You have the production.rb and development.rb files there. When you installed devise, you are made to include this config.action_mailer.default_url_options = { host: 'localhost', port: 3000 } in your development.rb file, this is for sending password confirmation link and reset password link.
Did you include this same in your production.rb file? If you are hosting on heroku, it should be the link of your app.
Please try this config in your heroku app.
config.action_mailer.default_url_options = { :host => 'myapp.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default :charset => "utf-8"
config.action_mailer.smtp_settings = {
address: "smtp.gmail.com",
port: 587,
domain: "myapp.herokuapp.com",
authentication: "plain",
enable_starttls_auto: true,
user_name: ENV["GMAIL_USERNAME"],
password: ENV["GMAIL_PASSWORD"]
}
My error was caused by the Searchkick gem which doesn't work with the trial version of the Searchbox addon in Heroku. I only noticed when I tried to add the secret_key_base environment variable to Devise's initializer file and started to see a reindexing error in Heroku's logs when I tried to reset a password. Commenting out the searchkick line in my models resolved the problem and I can now log in, &c.

Error TypeError: can't dup NilClass - Stripe

I am getting an error ERROR TypeError: can't dup NilClass when processing a Strip charge. I have followed the rails stripe integration documentation.
The error from the terminal is:
Started POST "/charges" for ::1 at 2016-05-27 12:35:48 +0100
Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"URydkbi6DghMZnzVqbf79KU+YRy/T+9g3UQ8tO8HTXG4uqvEMzdm6V/EjseNiZiIPS3ziOJJTpJ1K+gGMipksg==", "stripeToken"=>"tok_18FjA2JxArkI2Z35Q4MB3sCE", "stripeTokenType"=>"card", "stripeEmail"=>"fergusmorton#live.com"}
[2016-05-27 12:35:48] ERROR TypeError: can't dup NilClass
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httprequest.rb:392:in `dup'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httprequest.rb:392:in `meta_vars'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:59:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
Completed 500 Internal Server Error in 55ms (ActiveRecord: 0.0ms)
Net::HTTPFatalError (500 "Internal Server Error "):
app/controllers/charges_controller.rb:9:in `create'
Net::HTTPFatalError: 500 "Internal Server Error "
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http/response.rb:119:in `error!'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http/response.rb:128:in `value'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:915:in `connect'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:863:in `do_start'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/net/http.rb:852:in `start'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:413:in `transmit'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:176:in `execute'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rest-client-1.8.0-x86-mingw32/lib/restclient/request.rb:41:in `execute'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:298:in `execute_request'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:196:in `execute_request_with_rescues'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe.rb:148:in `request'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe/api_operations/request.rb:15:in `request'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/stripe-1.43.0/lib/stripe/api_operations/create.rb:5:in `create'
from C:/Users/Fergus/best-ever-me-v-1.1/app/controllers/charges_controller.rb:9:in `create'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb:198:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rendering.rb:10:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:117:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:505:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:92:in `__run_callbacks__'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/callbacks.rb:19:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rescue.rb:29:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `block in instrument'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/notifications.rb:164:in `instrument'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/abstract_controller/base.rb:137:in `process'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionview-4.2.5/lib/action_view/rendering.rb:30:in `process'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal.rb:196:in `dispatch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_controller/metal.rb:237:in `block in action'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:76:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:76:in `dispatch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:45:in `serve'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:43:in `block in serve'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:30:in `each'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/journey/router.rb:30:in `serve'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/routing/route_set.rb:817:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/etag.rb:24:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/conditionalget.rb:38:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/head.rb:13:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/params_parser.rb:27:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/flash.rb:260:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:225:in `context'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/session/abstract/id.rb:220:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/cookies.rb:560:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/query_cache.rb:36:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:377:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:88:in `__run_callbacks__'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/callbacks.rb:81:in `run_callbacks'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/reloader.rb:73:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:28:in `block in call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `catch'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.3.0/lib/web_console/middleware.rb:18:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:38:in `call_app'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:20:in `block in call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:68:in `block in tagged'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:26:in `tagged'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/tagged_logging.rb:68:in `tagged'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/rack/logger.rb:20:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/request_id.rb:21:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/methodoverride.rb:22:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/runtime.rb:18:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/activesupport-4.2.5/lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/actionpack-4.2.5/lib/action_dispatch/middleware/static.rb:116:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/sendfile.rb:113:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/engine.rb:518:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/railties-4.2.5/lib/rails/application.rb:165:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/lock.rb:17:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/content_length.rb:15:in `call'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/rack-1.6.4/lib/rack/handler/webrick.rb:88:in `service'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:138:in `service'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/httpserver.rb:94:in `run'
from C:/RailsInstaller/Ruby2.1.0/lib/ruby/2.1.0/webrick/server.rb:295:in `block in start_thread'
charges_controller.rb
class ChargesController < ApplicationController
def new
end
def create
# Amount in cents
#amount = 500
customer = Stripe::Customer.create(
:email => params[:stripeEmail],
:source => params[:stripeToken]
)
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => #amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
end
initiliazers/stripe.rb
Rails.configuration.stripe = {
:publishable_key => ENV['PUBLISHABLE_KEY'],
:secret_key => ENV['SECRET_KEY']
}
Stripe.api_key = Rails.configuration.stripe[:secret_key]
cart/show.html.erb
<div class="shopping-cart" style="margin-top:160px;">
<%= render "shopping_cart" %>
<%= form_tag charges_path do %>
<article>
<% if flash[:error].present? %>
<div id="error_explanation">
<p><%= flash[:error] %></p>
</div>
<% end %>
<label class="amount">
<span>Amount: €<%= current_order.subtotal %> </span>
</label>
</article>
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<%= Rails.configuration.stripe[:publishable_key] %>"
data-description="Cart Total"
data-amount="<%= current_order.subtotal %>"
data-locale="auto"></script>
<% end %>
</div>
Updated log Following Michael's Suggestions.
Started POST "/charges" for ::1 at 2016-05-31 11:45:45 +0100
Processing by ChargesController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"qXPL5OhG1UA+Ui4uyB7+80/UGDGXFPnOevOf/kmZhitA1f2xY8u9oS3w3DzsIJ2P18eKpcoSWDzSnEtMlLSv6A==", "stripeToken"=>"tok_18HANXJxArkI2Z35encjc3uW", "stripeTokenType"=>"card", "stripeEmail"=>"fergusmorton#live.com"}
Unpermitted parameters: utf8, authenticity_token, stripeTokenType
Completed 500 Internal Server Error in 6ms (ActiveRecord: 0.0ms)
NoMethodError (undefined method `stripe_customer_id' for nil:NilClass):
app/controllers/charges_controller.rb:15:in `create'
NoMethodError: undefined method `stripe_customer_id' for nil:NilClass
From the code that you've shown, it looks like you may have a couple of issues, but there may be additional issues related to setup for Stripe Payment.
The process for setting up Stripe within your application is covered here.
Setup Stripe in your Application
Add Stripe keys to your config/secrets.yml file:
development:
stripe_private_key: <%= ENV["STRIPE_PRIVATE_KEY"] %>
stripe_public_key: <%= ENV["STRIPE_PUBLIC_KEY"] %>
You can keep the STRIPE_PRIVATE_KEY and STRIPE_PUBLIC_KEY in your environment. Test and production environments would require similar configuration settings.
Make certain to add this code to your controller, or in any code that you intend to use the Stripe API:
require "stripe"
Stripe.api_key = Rails.application.secrets.stripe_private_key
Add a Migration to Add Stripe Customer ID to Customer
This migration provides an example based on a User class; your application may use a different model, so adjust as necessary to fit your purpose.
class AddUserStripeCustomerId < ActiveRecord::Migration
def change
change_table :users do |t|
t.string :stripe_customer_id, limit: 50, null: true
end
end
end
Create a Customer
When you're ready to begin the billing process for a customer, create the customer:
if !#user.stripe_customer_id
customer = Stripe::Customer.create(
:email => stripe_details[:stripeEmail],
:source => stripe_details[:stripeToken]
)
User.update(stripe_customer_id: customer)
end
Make sure to save the customer ID in your User model. You'll need to take care to not re-create and overwrite your customer ID for a user, because this is your tie-in to the Stripe payments system for that user.
Implement the Controller
The form elements (parameters) that you're submitting aren't scoped like a Rails model-based form. Typically, this is due to using a form_tag for a form that's not based directly on a model. This means that instead of having parameters scoped by a model hash, the parameters are unscoped.
Your strong parameters aren't included here, but they may be part of the issue. Make sure that you have the stripeToken and stripeEmail included in the permit list, like so:
params.permit(:stripeToken, :stripeCard, :stripeEmail)
Make certain to not include the typical require method on the strong parameters, as that validates that the parameters are scoped by a model object. In your create method, you should call the strong parameters method, and use the result, like so:
require "stripe"
class ChargesController < ApplicationController
Stripe.api_key = Rails.application.secrets.stripe_private_key
def new
end
def create
# Amount in cents
#amount = 500
stripe_details = stripe_params
if !#user.stripe_customer_id
customer = Stripe::Customer.create(
:email => stripe_details[:stripeEmail],
:source => stripe_details[:stripeToken]
)
User.update(stripe_customer_id: customer)
end
charge = Stripe::Charge.create(
:customer => customer.id,
:amount => #amount,
:description => 'Rails Stripe customer',
:currency => 'usd'
)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_charge_path
end
private
def stripe_params
params.permit(:stripeToken, :stripeCard, :stripeEmail)
end
end
More Information
Also check out How to create a charge and a customer in Stripe (Rails) for additional details on managing customer accounts and charges with Stripe.

Error while using Net::HTTP GET request

I am new to ruby . I have the following Code snippet which performs a GET operation and retrieves the names of my facebook groups
def get_groups
query=("SELECT gid,name FROM group where gid in(SELECT gid from group_member where uid=me)")
uri=URI("https://graph.facebook.com/fql")
params={'q'=>query,'access_token'=>TOKEN}
uri.query=URI.encode_www_form(params)
response=Net::HTTP.get_response(uri)
result=json.loads(response.text)
return result['data']
end
But when I execute the above code I get the following errors:
/usr/lib/ruby/1.9.1/net/protocol.rb:141:in `read_nonblock': Connection reset by peer (Errno::ECONNRESET)
from /usr/lib/ruby/1.9.1/net/protocol.rb:141:in `rbuf_fill'
from /usr/lib/ruby/1.9.1/net/protocol.rb:122:in `readuntil'
from /usr/lib/ruby/1.9.1/net/protocol.rb:132:in `readline'
from /usr/lib/ruby/1.9.1/net/http.rb:2562:in `read_status_line'
from /usr/lib/ruby/1.9.1/net/http.rb:2551:in `read_new'
from /usr/lib/ruby/1.9.1/net/http.rb:1319:in `block in transport_request'
from /usr/lib/ruby/1.9.1/net/http.rb:1316:in `catch'
from /usr/lib/ruby/1.9.1/net/http.rb:1316:in `transport_request'
from /usr/lib/ruby/1.9.1/net/http.rb:1293:in `request'
from /usr/lib/ruby/1.9.1/net/http.rb:1195:in `request_get'
from /usr/lib/ruby/1.9.1/net/http.rb:455:in `block in get_response'
from /usr/lib/ruby/1.9.1/net/http.rb:745:in `start'
from /usr/lib/ruby/1.9.1/net/http.rb:454:in `get_response'
from fb.rb:12:in `get_groups'
from fb.rb:32:in `<main>'
What is the mistake that I am making here?
I believe the issue here is you're using an HTTP library to access an HTTPS service. These are fundamentally different things. Here's an HTTPS example:
require 'net/http'
require 'net/https'
http = Net::HTTP.new('www.example.com', 443)
http.use_ssl = true
http.ssl_version = :TLSv1
http.ciphers = "ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:-LOW"
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
req = Net::HTTP::Get.new('/', {'Content-Type' =>'application/json'})
http.start {|http| http.request(req) }
It seems like you have SSL certificate validation issue. Try to turn off SSL validation.
Net::HTTP.verify_mode = OpenSSL::SSL::VERIFY_NONE
If above helps you, possible root of the issue is current OpenSSL installation. Try to update it to the latest version.

Resources