[Rails] Re: null object pattern

2009-03-15 Thread Carlos Santana
I have a roles table and I check authorization as: def can_be_deleted_by?(user) return false if user.role.nil? valid_roles = %w{admin creator} return false unless user.username == self.creuser || valid_roles.include?(user.role.name) return true end One other thing I

[Rails] Re: null object pattern

2009-03-15 Thread Bharat
Hello Carlos, I am glad it worked for you. Access control is a fundamental requirement along with authentication. Jim Neath's Bort which is available on Github, packages Role Requirements written by Tim Harper along with Restful Authentication for creating a baseline application. Tim has done a

[Rails] Re: null object pattern

2009-03-14 Thread Carlos Santana
It worked.. Had a typo.. :( Thanks for the help. Carlos Santana wrote: > I put UnassignedUser class in a separate file and added > self.abstract_class = true and also included requirement of User class. > Still same error. > > Any more guidelines? > > CS. > > Frederick Cheung wrote: >> On Ma

[Rails] Re: null object pattern

2009-03-14 Thread Carlos Santana
I put UnassignedUser class in a separate file and added self.abstract_class = true and also included requirement of User class. Still same error. Any more guidelines? CS. Frederick Cheung wrote: > On Mar 14, 8:30�pm, Carlos Santana > wrote: >> MaD wrote: >> > UnassignedUser gets only loaded w

[Rails] Re: null object pattern

2009-03-14 Thread Frederick Cheung
On Mar 14, 8:30 pm, Carlos Santana wrote: > MaD wrote: > > UnassignedUser gets only loaded when User is loaded. put it in its own > > file and maybe add: > >   self.abstract_class = true > > Separate file in the model directory? > Yes. The think to understand is that if your app hits the const

[Rails] Re: null object pattern

2009-03-14 Thread Carlos Santana
In that case I won't get any user object. Basically I am trying to implement in my application as mentioned here: http://pivotallabs.com/users/nick/blog/articles/272-access-control-permissions-in-rails For this I have some instance methods in User class. So the 'do_somethin' is basically not op

[Rails] Re: null object pattern

2009-03-14 Thread bill walton
Hi Carlos, On Sat, 2009-03-14 at 21:30 +0100, Carlos Santana wrote: > My objective is to avoid nil object errors when no user is logged in - > i.e. when session[:user] is nil. > > However, I still need to call some instance methods on this object. > > Please suggest me how can I do this? I'm

[Rails] Re: null object pattern

2009-03-14 Thread Carlos Santana
MaD wrote: > If you have a construct like this (all in the same file): > > # app/models/user.rb > class User < ActiveRecord::Base > # ... > end > > class UnassignedUser < User > def self.shout > puts "yeah" > end > end > > script/console will behave like this: > >>

[Rails] Re: null object pattern

2009-03-14 Thread MaD
If you have a construct like this (all in the same file): # app/models/user.rb class User < ActiveRecord::Base # ... end class UnassignedUser < User def self.shout puts "yeah" end end script/console will behave like this: >> UnassignedUser.shout NameError: uninit