Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a public page in an app that uses devise

I'm using devise for Authentication in a Rails 4 app. Almost all of the app requires a user to be authenticated, however, there are a few 'public' pages (Terms and conditions - that kind of stuff).

Devise itself makes the sign up and sign in pages public, using prepend_before_filter :require_no_authentication. However, that method is intended only for devise controllers. And devise doesn't seem to provide a 'proper' way to make single actions public.

So, what's the best way to make just a couple of actions public?

The only ways I can think of so far is:

  1. To make a new public namespace, and have separate controllers for public actions, which inherit from a PublicController that does not execute before_filter :authenticate_user!

  2. Same as above, but ditch the inheritance and the namespace. So the PublicController could act as a bucket for anything that needs to be public - which at this stage isn't much.

Is there a better way to make individual actions public with devise?

like image 709
joshua.paling Avatar asked Feb 03 '26 04:02

joshua.paling


1 Answers

You can optionally use skip_before_action for the public controllers. Example from guides:

class LoginsController < ApplicationController
  skip_before_action :require_login, only: [:new, :create]
end
like image 54
pedrofs Avatar answered Feb 04 '26 17:02

pedrofs



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!