Underscore character in session var

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?

are you sure ? i use :user_id


@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…

Are you sure you don’t unset :user_id, or set :userid in a filter/other

@session might not be a hash, but I think you can do:


If you need that.

And you can do:

before_filter(:except => [:login,:logout]) {

But what are you doing in the authorize_by_type method? Does that method


before_filter(:except => [:login, :logout]) {

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

;-). So you COULD do:


And check in that method:

def authorize_by_type(type)
if type == 1

elseif …


But this is better:

def authorize_by_type(type)
if type == :administrator

elseif …


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]) {

i get a syntax error, also when i do this:

before_filter(:except => [:login, :logout]) {


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


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 =>
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 %>

That doesnt work somehow.

So heres the deal:

application.rb has:

def authorize_by_type(name)


in my user_controller i want to use the authorize_by_type method from the

before_filter(:except => [:login, :logout]) {

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs