ruby on rails - User Authorization with CanCan: NoMethodError -
im using cancan authorization in app. have of each users information stored @ /users/2 or users/3 or /users/4 , on.
my problem when user logs in can amend url , see other users sensitive content. how can use cancan prevent user (say users/2) seeing (users/3) ?
when add "load_and_authorize_resource" users controller following error:
nomethoderror in userscontroller#show undefined method `user_id' #<user:0x007fee61e90b90> models
class ability include cancan::ability def initialize(user) user ||= user.new # guest user (not logged in) if user.has_role? :admin can :manage, :all can :access, :rails_admin can :dashboard else can :manage, user, :user_id => user.id end controllers
class applicationcontroller < actioncontroller::base protect_from_forgery rescue_from cancan::accessdenied |exception| redirect_to root_path, :alert => exception.message end class userscontroller < applicationcontroller before_filter :authenticate_user! load_and_authorize_resource def show @user = user.find(params[:id]) @date = params[:month] ? date.parse("#{params[:month]}-01") : date.today @occasions = @user.occasions.page(params[:page]).per(5) end
have tried put load_and_authorize_resource @ top of userscontroller?
Comments
Post a Comment