Dario
Dario

Reputation: 995

Restrict access to page using devise

I have installed devise and would like to restrict access to certain pages depending on whether the user has authenticated.

My first approach was to open each view, and add:

<% if mpuser_signed_in? %>
    #rest of code
 <%end>

(My model is called mpusers)

But I thought there maybe is a more elegant solution?

Dario

Upvotes: 1

Views: 3278

Answers (1)

tirdadc
tirdadc

Reputation: 4713

Set before_filter :authenticate_user! in the controller for the actions that require an authenticated user. In this example, we need the user to be authenticated for creation, edit and destroy actions.

class YourController < ApplicationController
  before_filter :authenticate_user!, only: [:new, :edit, :update, :destroy]

Upvotes: 5

Related Questions