What is the best way to bypass devise authorization for a specific record marked public

后端 未结 2 2136
南笙
南笙 2021-02-13 22:53

I\'m using devise and cancan in a Rails 3.2 project. I have an event model with a boolean flag public. If the event is marked as public

2条回答
  •  不思量自难忘°
    2021-02-13 23:36

    You can do that by skip the authenticate_user! in case of you have this args

      skip_before_filter :authenticate_user!, :only => :show, :if => lambda { 
        if params[:id]
          @event = Event.find(params[:id])
          @event and @event.public?
        else
          false
        end
      }
    

提交回复
热议问题