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

I am using an authentication program in a Rails 4 application. Nearly all applications require user authentication, but there are a few "public" pages (Terms and Conditions).

Come up with pages sign up

and sign in

using prepend_before_filter :require_no_authentication

. However, this method is only for developing controllers . And the development doesn't seem to provide the "correct" way to make individual actions public.

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

The only ways I can think of are:

  • To create a new namespace public

    and have separate controllers for public actions that inherit from PublicController

    which does notbefore_filter :authenticate_user!

  • Same as above, but inherit inheritance and namespace. Thus, it PublicController

    can act as a bucket for everything that should be publicly available, which is not much at this stage.

Is there a better way to make individual activities public using development?


source to share

2 answers

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

class LoginsController < ApplicationController
  skip_before_action :require_login, only: [:new, :create]




In your controller, you want:

before_action :authenticate_user!, :except => [:index]


This will execute the method :authenticate_user!

for all actions except the action index

. You can find more explanation on this.



All Articles