All steps are complete and checked off but app has error message:
Could you please copy/paste in your
I think maybe you meant app/controllers/application_controller.rb for the second one. There is no "app/models/application.rb"...
class ApplicationController < ActionController::Base def current_user @current_user ||= User.find(session[:user_id]) if session[:user_id] end def require_user redirect_to '/login' unless current_user end # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception end
@lenkie Good job formatting your code - just remember to put the backticks (
`) on their own line before and after the code
And you're correct about the file, thanks for pointing that out. Try adding this line to line 2 of
OK thanks. That helped bring up the login screen but when I log in, it says "Not found"...
@lenkie Could you post a screenshot?
Also, if I could see your
config/routes.rb, I think that's where the problem is
get 'albums' => 'albums#index'
get 'albums/new' => 'albums#new'
get 'albums/:id' => 'albums#show', as: :album
post 'albums' => 'albums#create'
get 'signup' => 'users#new'
get '/login' => 'sessions#new'
post 'login' => 'sessions#create'
delete 'logout' => 'sessions#destroy'
@lenkie Hm, so far, all of your code looks fine
If refreshing your browser doesn't change anything, could you post your
class SessionsController < ApplicationController def new end def create @user = User.find_by_email(params[:session][:email]) if @user && @user.authenticate(params[:session][:password]) session[:user_id] = @user.id redirect_to '/' else redirect_to 'login' end end def destroy session[:user_id] = nil redirect_to '/' end end
@lenkie I'm not finding any problems in your code, so I'm not sure what's wrong
You did create an account in the previous exercise (I think exercise 4), right? I don't think not having an account would cause an error, but I'm not sure what else the problem could be.
OK, I had already created an account but I went back and did it again, just to see if anything changed, and it did. So then I was able to sign in in step 11. Thanks. I guess there's some bug in the program or something. Anyway, moving on
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.