As the title suggests, Rails doesn't seem to recognize that a session is a special hash extended off of ActionController::Base. The error tells me either session is unrecognized or session is an array that doesn't accept symbols as a parameter.
I use before_filter and session as following: I have several user controllers extending off of each other, like this: AdminController < ModeraterController, ModeraterController < MemberController, MemberController < ApplicationController.
In each controller, I either have a before_filter block saying something like: before_filter do |controller| unless session[:member_id] redirect_to :controller=>'login' end if controller.action_name=='edit_profile' unless params[:id]==session[:member_id] flash[:notice]="You can't edit someone else's profile" #some redirect command end end end
I also tried the class method (with the self.filter(controller) method), but with no avail, so I was wondering: 1) are you allowed to have more than one method of before_filter in one controller? For example, is this valid?: TempController < ApplicationController before_filter :filter1, :only=>'method1' before_filter :filter2, :except=>'method1' #bunch of methods end
2) why isn't session recognized in the before_filter block method? 3) I'm guessing the reason why the class method isn't working is because I didn't extend it off of ApplicationController (though it is classes floating in a Controller). If this is so, can I do something like?: TempController < ApplicationController before_filter :self #bunch of methods self.filter(controller) #whatever end end
Thanks for the help!