Search code examples
ruby-on-railsdevisecancan

Skip Login For a Particular Action of a Particular Controller Rails


I am using Devise and CanCan in my rails application. My problem is that I want to make a particular action (basket_public_url) for a particular controller (BasketsController) public. I know how to skip controllers for authorization. Is there a way around?

https://github.com/ryanb/cancan/wiki/Ensure-Authorization#conditionally-check-authorization


Solution

  • If you want to skip login, this means you want to bypass both authentication and authorization.

    class BasketsController < ApplicationController
      skip_before_action :authenticate_user!, :only => :basket_public_url
      skip_authorize_resource :only => :basket_public_url
    
    end