Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Jose Borja
Jose Borja
17,676 Points

ajax 'Add Friend' button works fine locally but not on Heroku

When I try to add a friend locally when I click the button 'Add Friend' it works and switches to a green 'Friend Requested', but after deploying on Heroku the 'Add Friend' does not work and does not change state to 'Friend Requested'.

Using Chrome Dev tools console it shows a POST 500 (Internal Server Error).

Any help is greatly appreciated.

3 Answers

Chris McKnight
Chris McKnight
11,045 Points

You are trying to send an email and it is failing since heroku doesn't handle emailing. You need to add and configure an external mail service addon

Chris McKnight
Chris McKnight
11,045 Points

Can you give the output of running heroku logs?

Jose Borja
Jose Borja
17,676 Points
<p>2013-12-06T02:23:52.221311+00:00 heroku[router]: at=info method=GET path=/feed host=chak-treebook.herokuapp.com fwd="75.74.72.56" dyno=web.1 connect=1ms service=34ms status=200 bytes=2474
2013-12-06T02:23:36.025138+00:00 heroku[router]: at=info method=GET path=/user_friendships.json host=chak-treebook.herokuapp.com fwd="75.74.72.56" dyno=web.1 connect=10ms service=32ms status=304 bytes=0
2013-12-06T02:23:58.299589+00:00 heroku[router]: at=info method=GET path=/assets/application-1a8cf2729efb670eed7c3172cb6bffeb.css host=chak-treebook.herokuapp.com fwd="75.74.72.56" dyno=web.1 connect=47ms service=108ms status=304 bytes=0
2013-12-06T02:23:46.476948+00:00 heroku[router]: at=info method=GET path=/user_friendships?list=pending host=chak-treebook.herokuapp.com fwd="75.74.72.56" dyno=web.1 connect=1ms service=21ms status=200 bytes=1271
2013-12-06T02:48:18.223955+00:00 app[web.1]: Started POST "/user_friendships?user_friendship%5Bfriend_id%5D=chakaitos" for 75.74.72.56 at 2013-12-06 02:48:18 +0000
2013-12-06T02:48:18.227938+00:00 app[web.1]:   Parameters: {"user_friendship"=>{"friend_id"=>"chakaitos"}}
2013-12-06T02:48:18.227938+00:00 app[web.1]: Processing by UserFriendshipsController#create as JSON
2013-12-06T02:48:18.284864+00:00 app[web.1]:   Rendered user_notifier/friend_requested.html.erb (0.1ms)
2013-12-06T02:48:18.293485+00:00 app[web.1]: 
2013-12-06T02:48:18.297687+00:00 app[web.1]: 
2013-12-06T02:48:18.297687+00:00 app[web.1]: Errno::ECONNREFUSED (Connection refused - connect(2)):
2013-12-06T02:48:18.297687+00:00 app[web.1]:   app/models/user_friendship.rb:32:in `block in request'
2013-12-06T02:48:18.297687+00:00 app[web.1]: 
2013-12-06T02:48:18.297687+00:00 app[web.1]:   app/models/user_friendship.rb:28:in `request'
2013-12-06T02:48:18.293485+00:00 app[web.1]: Sent mail to chakaitos@gmail.com (7ms)
2013-12-06T02:48:18.296345+00:00 app[web.1]: Completed 500 Internal Server Error in 68ms
2013-12-06T02:48:18.297687+00:00 app[web.1]:   app/models/user_friendship.rb:45:in `send_request_email'
2013-12-06T02:48:18.297687+00:00 app[web.1]: 
2013-12-06T02:48:18.297687+00:00 app[web.1]:   app/controllers/user_friendships_controller.rb:45:in `create'
2013-12-06T02:48:18.316342+00:00 heroku[router]: at=info method=POST path=/user_friendships?user_friendship%5Bfriend_id%5D=chakaitos host=chak-treebook.herokuapp.com fwd="75.74.72.56" dyno=web.1 connect=5ms service=84ms status=500 bytes=643
[Chakaitos ~/Projects/treebook] (master)$ </p>