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
Naomi Freeman
Treehouse Guest TeacherError accepting friendships
I am working on the social features in the Treebook project. My friendships were coming along fine, if a little quirky right up until the final step, where you set the code to "accept" the friendship. All the pieces of the process work, until that mutual_friendship thing is supposed to happen.
I think the problem may be that the methods aren't available to an other class. Any thoughts on how I'd fix that? With @, but where?
If you think it's something else entirely, do let me know. Thanks!
Here's my error: (please note the code it is showing the error for is NOT in the UserFriendshipsController, but is in the user_friendships model)
NoMethodError in UserFriendshipsController#accept undefined method `accept_mutual_friendship?' for #<UserFriendship:0x00000103b72c68>
Extracted source (around line #10): 8 9 10 11 12 13 def accept @user_friendship = current_user.user_friendships.find(params[:id]) if @user_friendship.accept_mutual_friendship? flash[:success] = "You are now friends with # {@user_friendship.user.first_name}!" else flash[:error] = "They think you're a creep."
Rails.root: /Users/naomifreeman/Projects/laughing-wookie
Application Trace | Framework Trace | Full Trace app/controllers/user_friendships_controller.rb:10:in `accept' Request
Parameters:
{"utf8"=>"?", "_method"=>"put", "authenticity_token"=>"i8C62ZtgK/PVG2Vf5AzszVqvTSX5AKQhhvDa+SY27Wk=", "commit"=>"Accept Friendship", "id"=>"28"} Toggle session dump Toggle env dump Response
Headers:
None
1 Answer
Naomi Freeman
Treehouse Guest TeacherFixed it.
Had to put a ! at the end of the method accept_mutual_friendship
Video doesn't explain it. Shows up in "destroy friendship" video. You can just see it as you're typing other stuff.
I didn't realized you need to make methods know they're dangerous.
Naomi Freeman
Treehouse Guest TeacherNaomi Freeman
Treehouse Guest TeacherI can't edit at the moment :/
Here's the model code:
class UserFriendship < ActiveRecord::Base belongs_to :user belongs_to :friend, class_name: 'User', foreign_key: 'friend_id'
end
Here's the controller:
class UserFriendshipsController < ApplicationController before_filter :authenticate_user!
end