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 trialFausto Teles
1,419 PointsGuys, I can't figure out what's wrong with my code in "Saving Models and Redirecting - Challange Task 1 of 3".
The challenge asks: Set the flash success message to "Friendship created." if the @user_friendship is saved.
I tried several codes and none have worked. I think the code attached should work, but it doesn't.
class UserFriendshipsController < ApplicationController
def create
if @user_friendship.save
flash[:success] = "Friendship created."
end
end
end
2 Answers
Paul Ogawa
6,570 PointsYou have to create the @user first
class UserFriendshipsController < ApplicationController
def create
@user_friendship=User.new
if @user_friendship.save
flash[:success] = "Friendship created."
end
end
end
Jonathan Chua
4,136 PointsIt works!
Fausto Teles
1,419 PointsYeah!! Thanks!
Fausto Teles
1,419 PointsAt least we're not alone then :)
Jonathan Chua
4,136 PointsJonathan Chua
4,136 PointsSorry, I tried lots of code combos too, but can't get the challenge to pass... Maybe the Treehouse guys need to look at this.