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 Build a Rails API Authorization and Authentication Basic Authentication: Part 3

It seems like those other users are still showing

In this video, Naomi Freeman says something like "we can see that the lists belonging to other users are no longer showing. Great!" around the 2:45 mark.

However, it looks like there are a bunch of things marked with various user_ids, both in the video and in my own app. See?

Alt text

Did I miss something? Am I looking at the wrong user_id somehow?

Thanks!

2 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You seem to be right when it comes to the video. But when I tested my own implementation, it properly shows only the lists of the user I entered with the curl command, nothing more. I'm not sure if my code differs much from what Naomi did...

Hmm. Yeah, I got some "user_id: null" responses as well, but I also know that I have been typing a bunch of the curl requests incorrectly. :thumbsup: :grinning:

Alex Romanillos
Alex Romanillos
16,144 Points

The index method in the todo_list_controller.rb was left unedited:

class Api::TodoListsController < Api::ApiController

    def index
        Rails.logger.info "Current user: #{current_user.inspect}"
        render json: TodoList.all
    end

By replacing the query form TodoList.all to current_user.todo_lists.all the issue gets fixed.

class Api::TodoListsController < Api::ApiController

    def index
        Rails.logger.info "Current user: #{current_user.inspect}"
        render json: current_user.todo_lists.all
    end