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

Ruby Building Social Features in Ruby on Rails Building the Friendship UI Saving Models and Redirecting

Fausto Teles
Fausto Teles
1,419 Points

Guys, 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.

user_friendships_controller.rb
class UserFriendshipsController < ApplicationController
  def create
    if @user_friendship.save
      flash[:success] = "Friendship created."
    end
  end
end
Jonathan Chua
Jonathan Chua
4,136 Points

Sorry, I tried lots of code combos too, but can't get the challenge to pass... Maybe the Treehouse guys need to look at this.

2 Answers

You 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 
Fausto Teles
Fausto Teles
1,419 Points

At least we're not alone then :)