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 trialGlenn Barnard
3,668 PointsImplementing AJAX - Part 3 Issue - 500 Internal Server Error
I'm about 2:20 into the Part 3 video, where testing that the AJAX function on the button works, however, when I click the button (hoping it changes to "Friendship Requested), nothing happens, and the JS console is returning a 500 (Internal Server Error) message. This is when running on my localhost. I understand that this might happen after deploying to Heroku, but not sure why it would be happening on my local machine.
My Terminal outputs:
NoMethodError (undefined method email' for nil:NilClass):
app/mailers/user_notifier.rb:12:in
friend_requested'
app/models/user_friendship.rb:34:in send_request_email'
app/models/user_friendship.rb:27:in
block in request'
app/models/user_friendship.rb:23:in request'
app/controllers/user_friendships_controller.rb:37:in
create'
And my js developer console outputs:
POST http://localhost:3000/user_friendships?user_friendship%5Bfriend_id%5D= 500 (Internal Server Error) application.js?body=1:26 send application.js?body=1:26 ce.extend.ajax application.js?body=1:25 (anonymous function) user_friendships.js?body=1:6 ce.event.dispatch application.js?body=1:25 v.handle application.js?body=1:25
However, I can't seem to figure out exactly what is occurring. I've reset the databases multiple times and deleted and recreated various test profiles. Without AJAX, everything seems to work fine, but once I try to user_friendships.js, the error occurs.
Hopefully someone can help me figure this out.