I want simply Rails to redirect after a successful login to the previous location URI. It fails with a nice error (it is WebRick and latest Rails today updated): => Rails application started on http://0.0.0.0:3000 [2005-04-20 09:40:13] INFO WEBrick 1.3.1 [2005-04-20 09:40:13] INFO ruby 1.8.2 (2004-12-25) [powerpc- darwin8.0.0] [2005-04-20 09:40:13] INFO WEBrick::HTTPServer#start: pid=428 port=3000 127.0.0.1 - - [20/Apr/2005:09:40:14 CEST] "GET /operator/ HTTP/1.1" 302 71 - -> /operator/ 127.0.0.1 - - [20/Apr/2005:09:40:15 CEST] "GET /operator/login HTTP/ 1.1" 200 872 - -> /operator/login 127.0.0.1 - - [20/Apr/2005:09:40:20 CEST] "POST /operator/login HTTP/ 1.1" 302 71 127.0.0.1 - - [20/Apr/2005:09:40:20 CEST] "POST /operator/login HTTP/ 1.1" 302 71 http://127.0.0.1:3000/operator/login -> /operator/login #<ActionController::SessionRestoreError: Session contained objects where the class definition wasn''t available. Remember to require classes for all objects kept in the session. The session has been deleted. (Original exception: undefined class/module Operator [ArgumentError])> This code produces the bug: class OperatorController < ApplicationController before_filter :check_login def check_login if @session[:user].nil? if @session[:prev_loc].nil? @session[:prev_loc] = @request.request_uri redirect_to "login" end end end def login ... unless @session[:prev_loc].nil? redirect_to "index" <======= BAAAAAAANG!!! @session[:prev_loc] = nil end ... end Help meee! Gábor
On 2005.04.20., at 13:14, Michael Champanis wrote:> The important part is: > "Remember to require classes for all objects kept in the session." >Thanks, you showed me the light! :) Gábor _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
I haven''t looked into this problem enough to know whether or not require ''user'' will fix it, but I do know one thing for sure: you should never ever ever require ''user'', in Rails apps you want to require_dependency ''user'' (though I am skeptical this is necessary due to dependency injection). -Lucas http://www.rufy.com/ On Apr 20, 2005, at 4:14 AM, Michael Champanis wrote:> The important part is: > "Remember to require classes for all objects kept in the session." > > You''re going to need to put: > > require ''user'' and > model :user > > into app/controllers/application.rb > > i.e. > > <code> > require "user" > > class ApplicationController < ActionController::Base > model :user > end > </code> > > > Gábor Sebestyén wrote: >> I want simply Rails to redirect after a successful login to the >> previous location URI. It fails with a nice error (it is WebRick and >> latest Rails today updated): >> >> => Rails application started on http://0.0.0.0:3000 >> [2005-04-20 09:40:13] INFO WEBrick 1.3.1 >> [2005-04-20 09:40:13] INFO ruby 1.8.2 (2004-12-25) [powerpc- >> darwin8.0.0] >> [2005-04-20 09:40:13] INFO WEBrick::HTTPServer#start: pid=428 >> port=3000 >> 127.0.0.1 - - [20/Apr/2005:09:40:14 CEST] "GET /operator/ HTTP/1.1" >> 302 >> 71 - -> /operator/ >> 127.0.0.1 - - [20/Apr/2005:09:40:15 CEST] "GET /operator/login HTTP/ >> 1.1" 200 872 - -> /operator/login >> 127.0.0.1 - - [20/Apr/2005:09:40:20 CEST] "POST /operator/login HTTP/ >> 1.1" 302 71 >> 127.0.0.1 - - [20/Apr/2005:09:40:20 CEST] "POST /operator/login HTTP/ >> 1.1" 302 71 >> http://127.0.0.1:3000/operator/login -> /operator/login >> #<ActionController::SessionRestoreError: Session contained objects >> where the class definition wasn''t available. Remember to require >> classes for all objects kept in the session. The session has been >> deleted. (Original exception: undefined class/module Operator >> [ArgumentError])> >> >> >> This code produces the bug: >> >> class OperatorController < ApplicationController >> >> before_filter :check_login >> >> def check_login >> if @session[:user].nil? >> if @session[:prev_loc].nil? >> @session[:prev_loc] = @request.request_uri >> redirect_to "login" >> end >> end >> end >> >> def login >> ... >> unless @session[:prev_loc].nil? >> redirect_to "index" <======= BAAAAAAANG!!! >> @session[:prev_loc] = nil >> end >> ... >> end >> >> Help meee! >> >> Gábor_______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
The important part is: "Remember to require classes for all objects kept in the session." You''re going to need to put: require ''user'' and model :user into app/controllers/application.rb i.e. <code> require "user" class ApplicationController < ActionController::Base model :user end </code> Gábor Sebestyén wrote:> I want simply Rails to redirect after a successful login to the > previous location URI. It fails with a nice error (it is WebRick and > latest Rails today updated): > > => Rails application started on http://0.0.0.0:3000 > [2005-04-20 09:40:13] INFO WEBrick 1.3.1 > [2005-04-20 09:40:13] INFO ruby 1.8.2 (2004-12-25) [powerpc- darwin8.0.0] > [2005-04-20 09:40:13] INFO WEBrick::HTTPServer#start: pid=428 port=3000 > 127.0.0.1 - - [20/Apr/2005:09:40:14 CEST] "GET /operator/ HTTP/1.1" 302 > 71 - -> /operator/ > 127.0.0.1 - - [20/Apr/2005:09:40:15 CEST] "GET /operator/login HTTP/ > 1.1" 200 872 - -> /operator/login > 127.0.0.1 - - [20/Apr/2005:09:40:20 CEST] "POST /operator/login HTTP/ > 1.1" 302 71 > 127.0.0.1 - - [20/Apr/2005:09:40:20 CEST] "POST /operator/login HTTP/ > 1.1" 302 71 > http://127.0.0.1:3000/operator/login -> /operator/login > #<ActionController::SessionRestoreError: Session contained objects > where the class definition wasn''t available. Remember to require > classes for all objects kept in the session. The session has been > deleted. (Original exception: undefined class/module Operator > [ArgumentError])> > > > This code produces the bug: > > class OperatorController < ApplicationController > > before_filter :check_login > > def check_login > if @session[:user].nil? > if @session[:prev_loc].nil? > @session[:prev_loc] = @request.request_uri > redirect_to "login" > end > end > end > > def login > ... > unless @session[:prev_loc].nil? > redirect_to "index" <======= BAAAAAAANG!!! > @session[:prev_loc] = nil > end > ... > end > > Help meee! > > Gábor_______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails