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 User Authentication with Rails Password Resets and Testing Emailing Password Resets

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Whenever I render the application in the web browser I get an error message even after downloading the project files

Hi,

So after downloading the project files and then attempting to render the application in the browser at around 5:00 minutes in the video, I get an error in the browser saying:

"ActiveRecord::RecordNotFound in TodoListsController#index"

"Couldn't find User with id=3".

Followed by:

Extracted source (around line #14):

def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
  helper_method :current_user
app/controllers/application_controller.rb:14:in `current_user'

app/controllers/application_controller.rb:19:in `require_user'

Here's what the application_controll.rb file looks like:

class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception
  add_flash_types :success

  private
  def logged_in?
    current_user
  end
  helper_method :logged_in?

  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
  helper_method :current_user

  def require_user
    if current_user
      true
    else
      redirect_to new_user_session_path, notice: "You must be logged in to access that page."
    end
  end
end

Thanks!

Laura Cressman
Laura Cressman
12,548 Points

Did you copy the code exactly? It could be because your database isn't populated (for example, there is no user with the id of 3 if you haven't created any). If not I can go through with a finer comb!

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Laura Cressman I think you may be right. I did pretty much copy it. I downloaded the exact files and I never touched the application_controller.rb file. What could I do from the console to populate the database?

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

What steps did you take? You should download the file, extract it, go into the folder in your console, run bundle install, run rake db:migrate and then try rails s. localhost:3000 should now render the page properly.

alborz
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
alborz
Full Stack JavaScript Techdegree Graduate 30,885 Points

Hi Maciej Czuchnowski I deleted the entire app and downloaded the files again, did exactly the steps you outlined above, yet I still get the typical rails error displayed in the web browser:

"ActiveRecord::RecordNotFound in TodoListsController#index Couldn't find User with id=3".

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, I'll check it out and let you know what I find :)

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

OK, it works on my machine and the first thing it wants me to do is log in. So I assume you have an old cookie where your database id was 3 and it was not removed properly. Try running the localhost in another browser or incognito tab to see if that does the trick. If it does, you have to clean your cookies.