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
Kelley Kent
33,450 PointsRuby on Rails Code Challenge help
Hi there, I am on Building Social Features in Ruby on Rails-Managing Friendships and I am having trouble getting the correct answer on the code challenge: Adding States, task 2/2. It states Call the "block_mutual_friendship" method after the transition to the blocked state....here is the code I have:
class UserFriendship < ActiveRecord::Base
belongs_to :user
belongs_to :friend, class_name: 'User', foreign_key: 'friend_id'
state_machine :state, initial: :pending do
after_transition on: :block, do: [:block_mutual_friendship!]
state :requested
state :blocked
end
end
def block_mutual_friendship!
mutual_friendship.update_attribute(:state, 'blocked') if mutual_friendship
end
end
I'm not sure how to get the correct answer. Any help would be appreciated Thanks! -Kelley
2 Answers
Kelley Kent
33,450 PointsAh nevermind, I was going off of the project file and added the ! which wasn't needed. I figured it out.
Jason Seifer
Treehouse Guest TeacherGreat job, Kelley! Let us know if you have any more problems! :)