I got a strange error in Rails, I am creating an application in which users can register and upload files. Everything works, but when I want to download any file, the code in my application controller to check the active session does not work, because it cannot access the session array:
def current_user if session[:session].nil? # <- Fails here redirect_to "/login" else if session[:hash] == Digest::SHA512.hexdigest(session[:password]+" - "+session[:username]+" - "+session[:uuid]) #< and here (removing the other if) with NoMethodError return 0 else redirect_to "/login" end end end
This works for other things, but apparently breaks into POST requests. This is my HAML view for uploading files:
%b Upload %form{:action=>"/u",:method=>"post",:enctype=>"multipart/form-data"} %br %input{:type=>"file",:name=>"file"} %input{:type=>"submit",:value=>"Upload"}
What am I doing wrong? Also in POST requests, I ended up in the application log: WARNING: Can't verify CSRF token authenticity
source share