allegutta
allegutta

Reputation: 5644

Rails: Restrict access to specific pages

I followed this tutorial, and it works. But how can I restrict a page so that only users that are logged in can access it?

I wrote <% if current_user %> at the top of one page and if I tried to access it when I wasn't logged in, I could not access it (so this is one solution). But, is there a way I can do this in the controller? (I tried to use a before_filter as described in this post, but it did not work).

Upvotes: 0

Views: 2380

Answers (2)

Steve
Steve

Reputation: 2666

if using Devise, you can add

before_filter :authenticate_user!

to your controller.

Upvotes: 0

Trent Earl
Trent Earl

Reputation: 3607

You can use ActionController before_filter to validate the user by checking the existence of the current_user method.

Upvotes: 1

Related Questions