I stumbled across a weird problem i can do: @session[:userid] = 1 but cant: @session[:user_id] = 1 The second session var doesnt set. Is there a config setting for this? -- Posted via http://www.ruby-forum.com/.
are you sure ? i use :user_id On 1/15/06, tim vo <tim@depulz.nl> wrote:> > I stumbled across a weird problem > > i can do: > @session[:userid] = 1 > > but cant: > @session[:user_id] = 1 > > The second session var doesnt set. > Is there a config setting for this? > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060115/bcb54829/attachment.html
yes.. @session[:user_id] = 1 user_id: <%= @session[:user_id]%> wont work and @session[:userid] = 1 (in the controller) user_id: <%= @session[:userid]%> (in the view) does work... -- Posted via http://www.ruby-forum.com/.
Are you sure you don''t unset :user_id, or set :userid in a filter/other place? -- Posted via http://www.ruby-forum.com/.
Hmmm jup it unsetted somewhere :S Just blindly copied the code from the agile_web_development book... i have another question: in my application.rb file i have class ApplicationController < ActionController::Base def authorize_by_type(name) ..do stuff end end i want to use the authorize_by_type method with the before_filter but my php syntaxed brain cant find the solution to that. It seems unpossible to me to get the name var put in. i tried: before_filter :authorize_by_type("administrator"), :except => [:login,:logout] before_filter(:except => [:login,:logout]) { authorize_by_type("administrator") } it doesnt work i cant also loop through the session data (after sessiondata has been set ofcourse) i tried this in my view <% for sess in @session %> <%= sess %> <% end %> -- Posted via http://www.ruby-forum.com/.
@session might not be a hash, but I think you can do: debug(@session) If you need that. And you can do: before_filter(:except => [:login,:logout]) { authorize_by_type("administrator") } But what are you doing in the authorize_by_type method? Does that method work? -- Posted via http://www.ruby-forum.com/.
PS: before_filter(:except => [:login, :logout]) { authorize_by_type(:administrator) } Is nicer because you are using a role (administrator), and there is only one role named administrator. I think a good rule is: Use symbols if you would use an integer in #{insert_bad_programming_language} ;-). So you COULD do: authorize_by_type(1) And check in that method: def authorize_by_type(type) if type == 1 ... elseif ... ... end end But this is better: def authorize_by_type(type) if type == :administrator ... elseif ... ... end end -- Posted via http://www.ruby-forum.com/.
That doesnt work somehow.> So heres the deal:> application.rb has:def authorize_by_type(name) ... end> in my user_controller i want to use the authorize_by_type method from the > application_controller.before_filter(:except => [:login, :logout]) { authorize_by_type(:administrator) }> now i get this error:undefined method `authorize_by_type'' for UserController:Class> Doesnt a method from the application_controller need to know the > authorize_by_type method? Or do i have to get the method working with a : before > it?-- Posted via http://www.ruby-forum.com/.
> Because this works:before_filter :authorize, :except => [:login,:logout]> thats my other authorize method in the application controller. If so my problem > remains.. because when i do this:before_filter(:except => [:login, :logout]) { authorize_by_type(:administrator) }> i get a syntax error, also when i do this:before_filter(:except => [:login, :logout]) { :authorize_by_type(''administrator'') } -- Posted via http://www.ruby-forum.com/.