CanCan singleton loading with pluralized class name -
i'm experiencing issue latest version of cancan. seems gem won't load singleton resources pluralized names.
class preferences < activerecord::base self.table_name = 'preferences' belongs_to :user end class user < activerecord::base has_one :preferences end #controller class preferencescontroller < applicationcontroller before_filter :authenticate_user! #from devise load_and_authorize_resource :singleton => true, :through => :current_user, :through_association => :preferences, :parent => false end #ability.rb class ability include cancan::ability def initialize(user) can [:read, :update], preferences, :user_id => user.id end end
i maintain getting error when run controller spec:
failures: 1) preferencescontroller #show should homecoming http success failure/error: :show nameerror: uninitialized constant preference # ./spec/controllers/preferences_controller_spec.rb:10:in `block (3 levels) in <top (required)>'
it seems no matter combination of load_resource
arguments try, can't specs pass 1 time again without reverting loading resource manually this:
class preferencescontroller < applicationcontroller before_filter :authenticate_user! def show @preferences = current_user.preferences authorize! :read, @preferences end end
is there magic combination of load_and_authorize_resource
parameters need use? have same configuration working in singleton controller resource falls under normal rails conventions (i.e. user has_one :profile), know works under normal situations.
cancan
No comments:
Post a Comment