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
Jovani Perez
4,710 PointsCode challenge Friendability
Hey guys I'm stuck on adding controller methods on part 4 where it tells me to set the flash success message if the user_friendship variable was successfully blocked anyways here's the code that I have
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
end
any input would be greatly appreciated
3 Answers
George Offley
Courses Plus Student 7,386 PointsThe following code worked for me
def block
@user_friendship = current_user.user_friendships.find(params[:id])
if @user_friendship.block!
flash[:success] = "Successful."
else
flash[:error] = "That friendship could not be blocked."
end
redirect_to user_friendships_path
end
Sorry for the late reply but I only got to this challenge today!
Jovani Perez
4,710 Pointsanyone? lol
Jason Seifer
Treehouse Guest TeacherHi Jovani,
I think you need to call the block method with an exclamation point (block!). Hope that helps!