Reputation: 5644
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
Reputation: 2666
if using Devise, you can add
before_filter :authenticate_user!
to your controller.
Upvotes: 0
Reputation: 3607
You can use ActionController
before_filter to validate the user by checking the existence of the current_user
method.
Upvotes: 1