Can Authority Ruby Gem be used with logged out users? -


i following error:

  undefined method `can_read?' nil:nilclass 

..when trying access product page logged-out user. @ moment have

class productauthorizer < applicationauthorizer    def self.readable_by?(user)     true   end  end 

i'd allow non-logged in users see page. possible?

i tried changing default user method to:

config.user_method = :current_user ||= user.new 

however, causes problems, , server won't start.

ok found @ https://github.com/nathanl/authority/pull/32:

ok! sake of else reading issue, chris , chatted , agreed best way proceed. here's gist of it.

authority won't specially handle nil users or give specific option so. want limit authority authorization , keep authentication totally separate. if there's no user signed in, that's authentication concern; authority can't meaningfully answer question "can user x?" if isn't given user or quacks one.

besides philosophical point, having authentication handle better user experience. if admin has forgotten sign in , attempts admin-only action, confusing them "access denied". more helpful "please sign in".

what developers using authority can is:

have devise's before_filter :authenticate_user! running prior authority checks on request (since action requires authorization requires authentication). have user method return nulluser object quacks user, have authorizers know authority can improve error gives if pass nil or else doesn't quack user. chris going implement this.

hi i've put this

  class applicationcontroller < actioncontroller::base       def current_or_null_user         if current_user == nil           user.new         else           current_user         end      end   end 

...

authority.configure |config|    config.user_method = :current_or_null_user end 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -