Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 746
Hassam Sheikh Avatar asked Oct 19 '25 13:10

Hassam Sheikh


2 Answers

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
like image 122
Optimus Pette Avatar answered Oct 21 '25 03:10

Optimus Pette


If you are using CanCan 1.5 and higher, you can use skip_authorize_resource or skip_load_and_authorize_resource.

class BasketController < ApplicationController
  skip_authorize_resource :only => :basket_public_url
end

Reference link:

https://github.com/ryanb/cancan/wiki/authorizing-controller-actions

like image 36
Rohan Pujari Avatar answered Oct 21 '25 04:10

Rohan Pujari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!