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 trialNathan Mercado
Full Stack JavaScript Techdegree Student 14,819 PointsCode Challenge: Adding Controller Methods 4/5
Is there anything I'm missing on this code? I'm on part 4/5 of the CC, and it seems like whatever I do to change a small part of it. Nothing works.. I've gone back to the video several times to see if I was missing anything but there is nothing that I personally could not find.
Can anyone please help figure out what I'm missing here?
Here's the question:
Set the flash success message if the user_friendship variable was successfully blocked.
Here's the error:
Bummer! Try again!
Here's my code:
class UserFriendshipsController < ApplicationController
def block
@user_friendship = current_user.user_friendships.find(params[:id])
if @user_friendship.block!
respond_with user_friendship
flash[:success] = "You have blocked #{@user_friendship.friend.first_name}"
else
flash[:error] = "That friendship could not be blocked"
end
redirect_to user_friendships_path
end
7 Answers
Craig Booker
14,968 PointsSorry. I meant this, again.
class UserFriendshipsController < ApplicationController
def block @user_friendship = current_user.user_friendships.find(params[:id])
if @user_friendship.block!
flash[:success] = "You have blocked #{@user_friendship.friend.first_name}."
end
redirect_to user_friendships_path
end
end
Craig Booker
14,968 PointsThis passed.
class UserFriendshipsController < ApplicationController
def block
@user_friendship = current_user.user_friendships.find(params[:id])
if @user_friendship.block!
flash[:success] = "You have blocked someone."
end
end
end
Jason Seifer
Treehouse Guest TeacherHey Nathan Mercado it's a little hard to tell from the formatting but I think you may be missing a final "end" at the bottom. Give that a try and let me know how it goes.
Nathan Mercado
Full Stack JavaScript Techdegree Student 14,819 Points@Jason Seifer sorry I haven't responded to you for 15 days! I currently got back on and retried the code and I figure out what the problem was. I made the code way to complicated then it was suppose to be. I just had to remove the "else" statement and remove a "end" and bam I finished it.(:
Jason Seifer
Treehouse Guest TeacherGood work, Nathan Mercado!
Craig Booker
14,968 PointsStuck on this one as well part 4/5.
class UserFriendshipsController < ApplicationController
def block
@user_friendship = current_user.user_friendships.find(params[:id])
if @user_friendship.block!
flash[:success] = "You have blocked #{@user_friendship.friend.first_name}."
else
flash[:error] = "That friendship could not be blocked."
end
redirect_to user_friendships_path
end
end
Craig Booker
14,968 PointsTried this as well.
class UserFriendshipsController < ApplicationController
def block
@user_friendship = current_user.user_friendships.find(params[:id])
if @user_friendship.block!
flash[:success] = "You have blocked #{@user_friendship.friend.first_name}."
else
flash[:error] = "That friendship could not be blocked."
end
redirect_to user_friendships_path
end
end
Craig Booker
14,968 PointsSorry. I meant this. class UserFriendshipsController < ApplicationController def block @user_friendship = current_user.user_friendships.find(params[:id]) if @user_friendship.block flash[:success] = "You have blocked #{@user_friendship.friend.first_name}." end redirect_to user_friendships_path end end
Jason Seifer
Treehouse Guest TeacherGreat work, Craig Booker!
Nathan Mercado
Full Stack JavaScript Techdegree Student 14,819 PointsNathan Mercado
Full Stack JavaScript Techdegree Student 14,819 PointsIt's weird but this code is the one that passed for me.