user3763682
user3763682

Reputation: 441

devise - before filter in users controller and users scope in routes, correct implementation?, using rails

I use devise for authentication. In the users controller, I have:

before_filter :authenticate_user!

In the config/routes file, I have:

#DEVISE
devise_for :users
authenticated :user do
 resources :user
end

Do I really need the 'before_filter :authenticate_user!` in the users controller? Isn't it duplicative?

Thanks for your feedback.

Upvotes: 0

Views: 231

Answers (1)

rogMaHall
rogMaHall

Reputation: 691

No, having that code in both the controller and routes file is redundant. It's totally up to you and your design philosophy whether you go with authenticating in the controller files or routes file, but choosing one path will help you stay organized when your app grows.

Here's a good explanation from the Devise wiki of the difference between using the before_filter in controllers and and using authenticate, authenticated, and unauthenticated with resources.

Upvotes: 1

Related Questions