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

Rails gem acts_as_follower create/destroy error: Couldn't find Member(user) with id="username"

I'm not sure how to fix this error I'm getting when trying to create a follow relationship:

Couldn't find Member with id=testuser1

app/controllers/follows_controller.rb:6:in `create'

Parameters:

{"_method"=>"post",
"authenticity_token"=>"FnqLCCQYcFGMerOB56/G6dlPvzpPhPDFbxCXaiDBOUU=",
"member_id"=>"testuser1"}

Here's my controller:

class FollowsController < ApplicationController

before_filter :authenticate_member!

def create
    @member = Member.find(params[:member_id])
    current_member.follow(@member)
end

def destroy
    @member = Member.find(params[:member_id])
    current_member.stop_following(@member)
end

end

My links to follow/unfollow:

<%= link_to("Follow", member_follows_path(member.to_param), :method => :post, :class => "btn") %>

<%= link_to("Following", member_follow_path(member.to_param, current_member.get_follow(member).id), :method => :delete, :class => "btn btn-follow") %>

And how I defined my to_param since usernames are how you get to someones profile:

def to_param
  user_name
end

Anyone out there know how I can go about fixing this? Thanks.

1 Answer

Ok I figured this one out. I needed to remove the to_param from my links and pass the id instead.

Another way to do this would be to change the find in my controller to find_by_user_name