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?
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
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…
Are you sure you don’t unset :user_id, or set :userid in a filter/other
place?
@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?
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
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’)
}
=
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 %>
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?
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs