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
Andrew Goddard
40,807 PointsSaving Models and Redirecting Code Challenge Difficulties
I've been struggling away with this code challenge and, despite getting through most of the obstacles, I am now getting nowhere at the very last hurdle.
My code is below and the error message I'm getting is "No redirect occurred". I guess it's because I'm trying to redirect to @friend without setting @friend further up. However, everything I've tried in terms of setting @friend moves me back to the "Bummer" message, which makes me think I'm getting further away from the solution.
It may be something simple - I've been at this for over an hour, in no small part because of the bug in the Part 1 of 3 with the missing full stop, so it might just be that I'm staring the answer in the face.
Any help, gratefully received.
class UserFriendshipsController < ApplicationController def create @user_friendship = current_user.user_friendships.new(friend: @friend) if @user_friendship.save flash[:success] = "Friendship created." redirect_to profile_path(@friend) else flash[:error] = "There was a problem." end end end
4 Answers
Andrew Goddard
40,807 PointsSorry, I've no idea what happened with my code. Any tips on better ways to paste code would also be welcome. A
Andrew Goddard
40,807 PointsI've done this now, based on another forum. Thanks,
Itay Banner
1,922 PointsAndrew Goddard , for future reference, to create a code block in your messages you shoud indent it 4 spaces (or 1 tab), and make sure there's an empty line above and below your code. Hope this helps
Andrew Goddard
40,807 PointsHi Itay, thanks for this:
Hello world